The HTTP 307 Temporary Redirect status code indicates that the requested resource has been temporarily moved to another location.
When a server responds with this code, it provides the new URL in the “Location” header of the response.
Unlike 302 Found, 307 strictly maintains the original request method (GET, POST, etc.) when the browser makes the new request.
This is especially important to preserve the functionality of forms and other interactive elements.
The 307 signals to search engines that the resource will return to the original URL in the future, preventing the transfer of SEO value to the new temporary position.
It is commonly used during maintenance, A/B testing or temporary updates of web pages.
In what situations is it more useful to use 307 than 302
Redirection 307 is generally more useful than 302 in some specific situations:
Preservation of HTTP method
The main difference between 307 and 302 is that 307 strictly maintains the original HTTP request method (GET, POST, etc.) when the browser makes the new request.
This is especially important in the following cases:
- Handling of forms and interactive elements: When redirecting pages containing forms or other elements using specific HTTP methods such as POST.
- Migrations of sites with complex APIs: To ensure that API calls retain the correct request method after redirection.
Security
307 is preferable to 302 in terms of security because it does not allow the client to change the method on the redirected request.
This can be crucial for:
- Protection of sensitive data: Preventing POST requests from being converted to GET, reducing the risk of exposing sensitive information in the URL.
Specific technical scenarios
- Internal browser redirects: The 307 is used as an internal redirect when HTTP Strict Transport Security (HSTS) is enabled, forcing the HTTPS connection to increase security.
- Site maintenance with complex functionality: During upgrades or maintenance involving pages with advanced functionality that require specific HTTP methods.
Compatibility with HTTP/1.1
307 is specific to HTTP/1.1 and ensures consistent behavior in modern browsers, while 302 may be interpreted differently by older clients.
In general, 307 is preferred when it is essential to maintain the integrity of the HTTP request method and a more predictable and secure behavior is desired during temporary redirects.