What's the difference between a 302 and a 307 redirect?
307 came about because user agents adopted as a de facto behaviour to take POST requests that receive a 302 response and send a GET request to the Location response header.
That is the incorrect behaviour — only a 303 should cause a POST to turn into a GET. User agents should (but don't) stick with the POST method when requesting the new URL if the original POST request returned a 302.
307 was introduced to allow servers to make it clear to the user agent that a method change should not be made by the client when following the Location response header.
The difference concerns redirecting POST
, PUT
and DELETE
requests and what the expectations of the server are for the user agent behavior (RFC 2616
):
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.
Also, read Wikipedia article on the 30x redirection codes.
A good example of the 307 Internal Redirect
in action is when Google Chrome encounters a HTTP call to a domain it knows as requiring Strict Transport Security.
The browser redirects seamlessly, using the same method as the original call.