Redirects migrations struggle from Netlify to Vercel
Answered
French Lop posted this in #help-forum
French LopOP
Hello everyone,
I am having issues with migrating redirect paths from Netlify to Vercel.
I have some redirect paths that look like this:
from: /trips/cross-country-journey-winter-*
to: /print/cross-country-journey-winter-:splat
In Netlify these paths work perfectly fine since it supports the :splat but there is no equvivalent in Vercel. I tried following the existing documentation and tried a different couple approaches but no luck so far thats why I finally felt the need to get in touch with you and ask for help here!
I am having issues with migrating redirect paths from Netlify to Vercel.
I have some redirect paths that look like this:
from: /trips/cross-country-journey-winter-*
to: /print/cross-country-journey-winter-:splat
In Netlify these paths work perfectly fine since it supports the :splat but there is no equvivalent in Vercel. I tried following the existing documentation and tried a different couple approaches but no luck so far thats why I finally felt the need to get in touch with you and ask for help here!
Answered by riský
25 Replies
French LopOP
yesss!
Answer
wait can you even do that kind of redirect... you are doing inside the pathname
if it doesn't work, i would say you could use middlewire: https://nextjs.org/docs/app/building-your-application/routing/middleware and do the matcing and redirecting more manualy
French LopOP
yeah so in netlify you can, you can just have a wildcard at the path level but couldn't find something thats comparable in vercel
and you have tried it?
French LopOP
Yes thats right, in Netlify it works, I used to be on Netlify
migrating to vercel now after moving to ISR
I can look into the middleware you mentioned and see what that is
wait do, you are only want to redirect
cross-country-journey-winter to print, but it can have more content length after it?you might be able to abuse the regex also: https://nextjs.org/docs/app/api-reference/next-config-js/redirects#regex-path-matching
French LopOP
yeah so basically how it is, the /trips/cross-country-journey-winter-(4 different variations)
so after the - there could be 4 different variations and we know what they are, so maybe I can create a regex for those 4 different variations you think?
actually i don't know what extent the regex has... i was thinking of making it match the first bit
i mean, i would say that middlewire could be a better solution anyway... prob better DX (dev experience), and could be alot easier to modify then this rigid option
if the regex is the same as for the other matching, you might be able to do this...
French LopOP
yeah I think so, I looked into regex and seems like it matches full paths like after /(wildcard) and not like this /something-(wildcard)
that is what i think might occur too
French LopOP
can you link this please?
ahh yes, sorry: https://nextjs.org/docs/app/api-reference/next-config-js/redirects#header-cookie-and-query-matching (its the same page - just lower down)
French LopOP
no worries thanks alot btw! I'll check this out
i would say that midlewire has a higher chance of working, but this might...
French LopOP
Solved, had to use this:
ahh so you just needed to use
:splat or :slug instead of * and also use source and destination instead of from and to? (so the docs were right?)