Category: Next.js, React and TypeScript

Next.js trailingSlash Causes a Redirect Loop

Read this guide in Polish

Request /offer passes through another 308 and returns to the previous address. Next.js and external reverse proxy can enforce conflicting Slash rules at the end of URL.

How to identify the source of the problem

Check the full Location response chain for both address variants. Compare the traileringSlash setting in next.config with CDN, host and proxy rules.

Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.

Repair steps

Select one strategy to trackSlash and remove the opposing rule in the second layer of routing. Update internal links, canonical and sitemap to one version of the address.

How to Test Solution

Both variants end up on one target URL without a loop, and the page returns 200.

Security and restrictions

Do not try to silence the loop by ignoring the redirects in the crawler.