301Moved Permanently
This and all future requests should be directed to the given URI.
What this code obliges you to do
Safe to retry
Repeating the same request can succeed, so a client may back off and try again. Honour Retry-After when the response sends one.
Cacheable by default
RFC 9110 lists this code as heuristically cacheable, so a cache may store it even with no Cache-Control header. Send explicit headers if that is not what you want.
Body allowed
You may return a payload explaining the outcome — for an error, a machine-readable problem document is worth the effort.
May be rewritten to GET
User agents have long rewritten POST to GET when following this code, and the body is dropped. Use 307 or 308 if the method matters.
Target replaces the old URL
A permanent redirect tells search engines to move the URL and carry its ranking signals across. Use it for migrations you are not undoing.
When you see it
3Site migration
URL structure changes
HTTP to HTTPS redirect
Effect on search
Highly beneficial when changing URLs. Search engines will pass most/all link equity to the destination and replace the old URL in the index.
How to send it
2return NextResponse.redirect(newUrl, 301);return 301 https://$host$request_uri;Codes people confuse with this one
3Found
The requested resource resides temporarily under a different URI. Previously known as 'Moved Temporarily'.
Temporary Redirect
Similar to 302, but explicitly requires the client to retain the same HTTP method (e.g. POST remains POST) during the redirection.
Permanent Redirect
Similar to 301, but explicitly keeps the same HTTP method for the redirection.