Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

What is the difference between a 302 and 303 response?

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

  • 10.3.3 302 Found
  • 10.3.4 303 See Other

Are these interchangeable or why would one be used over the other? Could you please provide a use case of when one would be used (and the other would not) ?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

The description on the page to which you linked seem to be fairly descriptive of their intended purpose:

A 302 redirect indicates that the redirect is temporary -- clients should check back at the original URL in future requests.

A 303 redirect is meant to redirect a POST request to a GET resource (otherwise, the client assumes that the request method for the new location is the same as for the original resource).

If you're redirecting a client as part of your web application but expect them to always start at the web application (for example, a URL shortener), a 302 redirect seems to make sense. A 303 redirect is for use when you are receiving POST data from a client (e.g., a form submission) and you want to redirect them to a new web page to be retrieved using GET instead of POST (e.g., a standard page request).

But see this note from the status code definitions -- most clients will do the same thing for either a 302 or 303:

  Note: RFC 1945 and RFC 2068 specify that the client is not allowed
  to change the method on the redirected request.  However, most
  existing user agent implementations treat 302 as if it were a 303
  response, performing a GET on the Location field-value regardless
  of the original request method. The status codes 303 and 307 have
  been added for servers that wish to make unambiguously clear which
  kind of reaction is expected of the client.
share|improve this answer
    
Very clear example, thank you. –  David542 May 21 '12 at 19:43
2  
Clear but wrong. A 303 redirect is not permanent. The RFC states "The 303 response MUST NOT be cached". The description you have given here matches a 301 redirect. –  Ladadadada May 22 '12 at 10:04
1  
Mea culpa. I had 301 and 303 backwards. I've updated the answer. –  larsks May 22 '12 at 10:22

There are four different redirect types (currently). Originally there were only two but most clients implemented the 302 redirect incorrectly so two more were added to clarify the difference between the two different possible behaviours on receiving a 302.

The RFC you linked to states this in the section on 302 redirects:

  Note: RFC 1945 and RFC 2068 specify that the client is not allowed
  to change the method on the redirected request.  However, most
  existing user agent implementations treat 302 as if it were a 303
  response, performing a GET on the Location field-value regardless
  of the original request method. The status codes 303 and 307 have
  been added for servers that wish to make unambiguously clear which
  kind of reaction is expected of the client.
  1. A 301 redirect is a permanent redirect. It is cacheable and any bookmarks for this URL should be updated to point to the new URL.
  2. A 302 redirect is a temporary redirect. It is not cacheable by default and should be re-requested every time (but you can override this with caching headers). The follow-up request should use the same method (POST, GET, CONNECT, PUT, DELETE, etc.) as the original request and for anything other than GET and HEAD requests, the client should prompt the user before making the request. This is the part that the clients got wrong and most of them change the method for the follow-up request to GET, regardless of the original method.
  3. A 303 redirect is the same as a 302 except that the follow-up request is now explicitly changed to a GET request and no confirmation is required.
  4. A 307 redirect is the same as a 302 except that the follow-up request is now explicitly the same as the original request and confirmation must be acquired from the user for request methods other than GET and HEAD.

Older clients may not understand the 303 redirect. Anything that makes an HTTP/1.1 request should understand a 303 response.

It is possible to consider 300 and 305 responses to be a redirects, meaning that there are six different types.

share|improve this answer

Redirect types (301,302,303...) used have a lot of impact on how search engines will index and rank content. Some spiders might even refuse to index temporarily redirected content. Details can be found in various SEO literature...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.