Which redirect do I choose?
The 3xx
status-codes are a bit of a mess. There’s a lot of confusion and
mis-use, so I thought it might help to sum all of them up in a single article.
Choosing the right redirect
Are you responding to a POST
request, and instead of returning a status
immediately, you want to redirect the user to a confirmation page?
Use 303 See Other
.
Did the resource move to a new path, or a new domain, and you want to make sure that any HTTP client repeats the exact same HTTP request on the new location?
Use 307 Temporary Redirect
if the move was temporary, or
308 Permanent Redirect
if the move was permanent.
Did the resource move, but you only care about GET
request? (perhaps because
this is a website).
Use 302 Found
if the move was temporary, or
301 Moved Permanently
if the move was permanent.
Do you want to send the user somewhere else, but you’re not sure where because there’s more than one option, and you’d like the user to decide:
Use 300 Multiple Choices
.
References
- RFC7231, Section 6.4.1 - 300 Multiple Choices.
- RFC7231, Section 6.4.2 - 301 Moved Permantently.
- RFC7231, Section 6.4.3 - 302 Found.
- RFC7231, Section 6.4.4 - 303 See Other.
- RFC7231, Section 6.4.7 - 307 Temporary Redirect.
- RFC7238 - 308 Permanent Redirect.