Next.js Discord

Discord Forum

How to implement 301 redirection in Next13 (App)

Unanswered
Himalayan posted this in #help-forum
Open in Discord
Avatar
HimalayanOP
In docs permanentRedirect returns 308
Any cases to implement 301 code redirection?

9 Replies

Avatar
risky
Just use the normal redirect?
Avatar
HimalayanOP
@risky if I'm not mistaken a normal redirect return 307 (Temporary)
Avatar
risky
Yes
But you may not need 301
As do you want to redirect all http modes or just GET
https://nextjs.org/docs/app/api-reference/next-config-js/redirects
Why does Next.js use 307 and 308? Traditionally a 302 was used for a temporary redirect, and a 301 for a permanent redirect, but many browsers changed the request method of the redirect to GET, regardless of the original method. For example, if the browser made a request to POST /v1/users which returned status code 302 with location /v2/users, the subsequent request might be GET /v2/users instead of the expected POST /v2/users. Next.js uses the 307 temporary redirect, and 308 permanent redirect status codes to explicitly preserve the request method used.
Avatar
risky
But without weird things like middlewire I don't know if you can customise the status code for a page
Avatar
tafutada777
301 is cached in web browser so you can not purge it once cached. if you didn’t know.
Avatar
risky
ahh yes, i got the numbers mixed up, but still the nextjs article + what tafutada said