Nextjs returns a 308 redirect on #82874
-
Hey, Now I’ve added a subdomain (es.mydomain.com) that isn’t proxied through Cloudflare because Cloudflare caused issues with webhooks. Instead, I let Traefik handle it directly. I set up Traefik to rewrite requests like this:
Problem:When I visit https://es.mydomain.com/, instead of serving the response from /eventsub, Next.js responds with a 308 Permanent Redirect to /eventsub. So I always end up with: Instead of Next.js just handling the /eventsub route internally. Whats causing this 308 redirect? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
By default, Next.js normalizes paths by removing the trailing slash. For example,
To fix this problem, update your next.config.js like this:
With this setting, Next.js will keep the trailing slash in URLs, and the redirect will no longer occur. |
Beta Was this translation helpful? Give feedback.
By default, Next.js normalizes paths by removing the trailing slash. For example,
/eventsub/
is automatically redirected to/eventsub
. This is why you’re seeing the redirect.traefik.http.middlewares.es-internal-rewrite.replacepathregex.replacement=/eventsub/$$1
You are replacing it to /eventsub/ so nextjs is trying to remove the slash.
To fix this problem, update your next.config.js like this:
With this setting, Next.js will keep the trailing slash in URLs, and the redirect will no longer occur.