Regex Path Matching for Redirects
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
A common URL pattern for blogs and websites coming from Wordpress is /year/month/day/slug
. To redirect pages that match this to a different page, the path matching would look like this:
{
source: '/:year/:month/:day/:post',
destination: '/blog/:post',
permanent: true,
},
This however matches generated Next.js files (for example, /_next/static/css/b9c315e24bcc3c2b5b54.css
which results in effectively breaking the built website (dev mode doesn’t match this pattern).
Describe the solution you’d like
By adding more finegrained matchers like Regex strings, you could restrict the matching to look for numbers only. Using the example above, in the vercel.json
file I can currently write "\/\\d{4}\/\\d{2}\/\\d{2}\/(.+)\/?"
to only match blog posts.
Describe alternatives you’ve considered
I can achieve this by leveraging platform-specific files such as vercel.json
but it would be nice to have support for this out of the box!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Hi, this is supported in Next.js, see the example redirect below for matching all routes except
_next
. Note: therewrites
andredirects
support invercel.json
matches Next.js’ built-in supportIt does look like this isn’t documented, I opened a PR to mention this support here, thanks for bringing this up!