App router middleware rewrites not working with i18n enabled
Hello,
I'm trying to do rewrites through my middleware to App router pages cohabiting with page router pages
I made a repo reproducing the issue : https://github.com/mparisot-antescofo/netlify with a separate branch to add i18n to it : https://github.com/mparisot-antescofo/netlify/pull/4
On the main branch all is behaving as expected: rewrite to app router page : https://antescofo-test-netlify-rewrites.netlify.app/rewrite-app redirect to app router page : https://antescofo-test-netlify-rewrites.netlify.app/redirect-app rewrite to page route page : https://antescofo-test-netlify-rewrites.netlify.app/rewrite-page redirect to page router page : https://antescofo-test-netlify-rewrites.netlify.app/redirect-page
But on the branch https://deploy-preview-4--antescofo-test-netlify-rewrites.netlify.app which add the i18n config, the rewrite to app router page returns a 404 while all the others work as expected : https://deploy-preview-4--antescofo-test-netlify-rewrites.netlify.app/rewrite-app
I tried to disable the language detection or forcing the url.locale before the rewrite thinking it might be the issue but I have the same results
Note that I added an additional app subdirectory to be able to separate page and app routed pages in other places of my code
thank you
Hi @mparisot-antescofo!
Though this isn't documented, I believe Next.js itself does not really support i18n when mixing App Router and Pages Router: https://github.com/vercel/next.js/issues/57704#issuecomment-1902683396. 😞
Hope that link helps.
I think it is a different issue and the one you linked was part of the reason I had to add a subdirectory to distinguish between app and page router pages
In my case everything works fine in dev and build mode if I run things locally, it only fails when I deploy to netlify
The page also works fine if I call it directly, it only returns a 404 when I try to create a rewrite in my middleware and deploy it on netlify hence why I suspect it is an issue on your side
For now I changed my rewrite into a redirect as a workaround even though I would prefer not to expose those urls to the user