Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between HTTP redirect codes

People also ask

What is the difference between 301 302 and 307 redirect?

302s are often used to create temporary redirects, but, with the advent of HTTP 1.1, 307 has replaced it as a valid temporary redirect. While a 302 is a little vague, a 307 states precisely that the requested URL has been moved to a temporary location and will be back in a while.

What is the difference between 301 and 308 redirect?

The main difference between the 301 and 308 redirects is that when a 308 redirect code is specified, the client must repeat the exact same request (POST or GET) on the target location. For 301 redirect, the client may not necessarily follow the exact same request.

What's the difference between a 301 or 307 HTTP status code redirect?

301 Moved Permanently This and all future requests should be directed to the given URI. 307 Temporary Redirect (since HTTP/1.1) In this case, the request should be repeated with another URI; however, future requests should still use the original URI. Thanks for the answer.


  • 301: Permanent redirect. Clients making subsequent requests for this resource should use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
  • 302: Redirect for undefined reason. Clients making subsequent requests for this resource should not use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
  • 303: Redirect for undefined reason. Typically, 'Operation has completed, continue elsewhere.' Clients making subsequent requests for this resource should not use the new URI. Clients should follow the redirect for POST/PUT/DELETE requests, but use GET for the follow-up request.
  • 307: Temporary redirect. Resource may return to this location at a later point. Clients making subsequent requests for this resource should use the old URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.

I personally recommend avoiding 302 if you have the choice. Many clients do not follow the spec when they encounter a 302. For temporary redirects, you should use either 303 or 307, depending on what type of behavior you want on non-GET requests. Prefer 307 to 303 unless you need the alternate behavior on POST/PUT/DELETE.


The difference between 303 and 307 is this:

303: See other. The request is received correctly, but the results should be retrieved using a GET on the redirect url.

307: Temporary redirect. The entire request should be redirected to the new url. Any post data should be re-posted.

Note that 302 was intended to have the behavior of 307, but most browsers implemented it as the behavior of 303 (both of which didn't exist back then). Therefore, those two new codes were introduced to replace 302.

The difference between 301 and 303:

301: The document is moved. Future requests should use the new url. This url is obsolete.

Note: Be careful with this code. Browsers and proxies tend to apply really agressive caching on it, so if you reply with a 301 it might take a long while for someone to revisit that url.

303: The request is received correctly. Any PUT requests are processed. The resulting document can be retrieved from the redirect url. Future request should still go to the original url.