HTTP 302
{{short description|HTTP Status Code}}
{{HTTP}}
The HTTP response status code 302 Found is a common way of performing URL redirection. The HTTP/1.0 specification ({{IETF RFC|1945|link=no}}) initially defined this code, and gave it the description phrase "Moved Temporarily" rather than "Found".
An HTTP response with this status code will additionally provide a URL in the header field Location. This is an invitation to the user agent (e.g. a web browser) to make a second, otherwise identical, request to the new URL specified in the location field. The end result is a redirection to the new URL.
Many web browsers implemented this code in a manner that violated this standard, changing the request type of the new request to GET, regardless of the type employed in the original request (e.g. POST).{{cite web |last=Lawrence |first=Eric |url=http://blogs.msdn.com/b/ieinternals/archive/2011/08/19/understanding-the-impact-of-redirect-response-status-codes-on-http-methods-like-head-get-post-and-delete.aspx |work=EricLaw's IEInternals blog |access-date=2011-08-20 |title=HTTP Methods and Redirect Status Codes}} For this reason, HTTP/1.1 ({{IETF RFC|2616|link=no}}) added the new status codes 303 and 307 to disambiguate between the two behaviours, with 303 mandating the change of request type to GET, and 307 preserving the request type as originally sent. Despite the greater clarity provided by this disambiguation, the 302 code is still employed in web frameworks to preserve compatibility with browsers that do not implement the HTTP/1.1 specification.{{cite web|url=https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect |title=Request and response objects | Django documentation | Django |publisher=Docs.djangoproject.com |access-date=2014-06-23}}
As a consequence, {{IETF RFC|7231|link=no}} (the update of {{IETF RFC|2616|link=no}}) changes the definition to allow user agents to rewrite POST to GET.{{cite web|url=https://tools.ietf.org/html/rfc7231#section-6.4.3 |title=Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
|publisher=Tools.ietf.org |access-date=2019-01-05}}
Example
Client request:
GET /index.html HTTP/1.1
Host: www.example.com
Server response:
HTTP/1.1 302 Found
Location: http://www.iana.org/domains/example/
See also
References
{{Reflist}}
External links
- {{IETF RFC|9110|link=no}} HTTP Semantics