'Redirecting only subpaths in vercel.json? (Next.js)

Changing the structure of my site and am trying to redirect everything behind /blog to /. So /blog/some-blog-post should now go to /some-blog-post. I am doing this:

    {
        "source": "/blog/:path*",
        "destination": "/:path*"
    },

This works.

However, I want to keep my blog overview page at /blog. This breaks now though? How can I redirect everything behind blog back to root, but keep /blog?



Solution 1:[1]

You should remove the star in the end of the path, since it probably makes the path slug optional, meaning that the rule also applies to just /blog/ path as well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FINDarkside