Next.js Discord

Discord Forum

Prevent redirect from middleware if already redirected in next.config.js

Answered
Toy Fox Terrier posted this in #help-forum
Open in Discord
Toy Fox TerrierOP
I am doing redirects in next.config.js based on data in CMS (very much like Sanitypress does it https://github.com/nuotsu/sanitypress/blob/main/next.config.js) and also localization redirects in my middleware (if current path is not prefixed with locale e.g /en/ redirect to prefixed path).

Now I want to skip localization redirects if next.config.js has already redirected. Is there an easy way to detect this?

Or should I just move CMS redirects into the middleware, too? Would it have any downsides?
Answered by Toy Fox Terrier
Actually, seems like the middleware is not executed at all if next.config.js has already redirected . Apparently I had some other issue before in my tests and next.config.js redirects never kicked in and the middleware got involved. Case closed.
View full answer

1 Reply

Toy Fox TerrierOP
Actually, seems like the middleware is not executed at all if next.config.js has already redirected . Apparently I had some other issue before in my tests and next.config.js redirects never kicked in and the middleware got involved. Case closed.
Answer