Add statusCode Option to redirect Function in next/navigation. #76943
Amir-Mirkamali
started this conversation in
Ideas
Replies: 1 comment
-
Small correction -- Also, for the A/B test usecase, I'd recommend doing that in middleware anyway (rendering a page just to call redirect() is slow), and you can also control the exact status code there |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
I would like to request a feature enhancement for the redirect function in the next/navigation module of Next.js. The proposed enhancement is to add an optional statusCode parameter that allows developers to set the HTTP status code for the redirection explicitly.
Current Behavior:
Currently, the redirect function always uses a 308 (Permanent Redirect) status code . While this is suitable for most cases, there are scenarios where using a different status code (e.g., 301, 302) is necessary. Specifically, some search engines and crawlers still have issues with 308 redirects, potentially affecting SEO and content indexing.
This feature would be particularly useful in scenarios where:
• Temporary redirects (302) are needed during A/B testing or content experiments.
• Legacy URLs need permanent (301) redirects for better SEO without risking issues with search engines that do not fully support 308 status codes.
• Handling edge cases where 307 or other redirection codes are required for specific integrations.
Background
By adding the statusCode parameter to the redirect function, Next.js would offer greater flexibility to developers, helping them avoid potential SEO pitfalls and enabling finer control over HTTP responses.
Proposal
Thank you for considering this enhancement. I am looking forward to your feedback!
Beta Was this translation helpful? Give feedback.
All reactions