307 Status Code - Temporary Redirect
This section provides an in-depth look at the 307 Status Code, known as Temporary Redirect. You'll learn its definition, explore its key components, and examine practical examples and use cases. Understanding the 307 Status Code is crucial for managing temporary URL redirections in web development, ensuring users and search engines are directed to the correct resource without affecting the request method used.
What is 307 HTTP Status Code
The HTTP Status Code 307, known as "Temporary Redirect", is a redirection response status code. It indicates that the client must send its request to a different location, but future requests should still use the original URI. This redirection is only temporary. Notably 307 Temporary Redirect
ensures that the method and the body of the original request are preserved when the redirection is followed.
Understanding 307 Temporary Redirect
Temporary Redirection: The
307 Temporary Redirect
response code communicates that the resource the client is seeking has been temporarily relocated to another URI, but this change isn't permanent.
Location Header: This header typically accompanies the 307 Temporary Redirect status code, indicating the temporary URI where the requested resource can currently be accessed.
Why 307 Temporary Redirect?
The 307 Temporary Redirect
is especially useful when there's a need for temporary redirection without altering the request method or body. This can be beneficial during server maintenance or when a resource is temporarily available under a different URI.
Characteristics of 307 Temporary Redirect
Method Preservation: Unlike some other redirects, the
307 Temporary Redirect
ensures that the HTTP method (likeGET
,POST
,PUT
, etc.) remains the same when the client follows the redirect. For example, if the original request was aPOST
, the redirected request will also be aPOST
.Temporary Nature: This code is used for temporary redirections only. Clients should continue to use the original URI for future requests.
How does 307 Temporary Redirect Work?
Client Sends a Request:
The client sends a request to a specific resource on the server using a URL.
Server Sends a Response:
The server determines that the resource has been temporarily moved and returns a
307 Temporary Redirect
response, along with aLocation
header pointing to the new URI.
Components of a 307 Temporary Redirect Response
In a 307 Temporary Redirect
response, you'll often find:
Status Line: Indicating the
307 Temporary Redirect
status code.
Headers: The
Location
header is crucial, signaling the new temporary URI where the resource can be accessed.
Example of 307 Temporary Redirect
Suppose a bank customer
tries to access their account statement through the bank's web application. However, due to server maintenance or updates, the specific page for account statements has been temporarily moved to another URL. When the customer clicks on the link to view their statement, the server responds with a 307 http status code, along with a Location header pointing to the new, temporary URL where the account statements can be accessed.
Form Submission during Maintenance:
Response:
The client (bank customer) sends a GET request to access their account statements.
The server, due to ongoing maintenance, responds with a 307 status code, indicating a temporary redirect.
The
Location
header specifies the temporary URL where the account statements can be accessed during this period.Once the maintenance is over, the server will stop sending the 307 redirect, and the original URL will serve the account statements again.
This ensures that the customer's request is seamlessly redirected to the correct page without any disruption in their experience, and without changing the nature of their original request (like keeping it a GET request). Once the maintenance is completed, the redirect will be removed, and requests will again be served from the original URL.
Use Cases of 307 Redirect
E-Commerce Site Maintenance: During website updates, an e-commerce site might use a 307 redirect to temporarily send customers from a product page to a maintenance notice page, ensuring they know when to come back for purchases.
Form Submission During Backend Changes: If a website is updating its data processing backend, a 307 redirect can temporarily redirect form submissions to a different server or endpoint, ensuring that user submissions are not lost and are processed correctly.
A/B Testing: For conducting A/B tests on a webpage, a 307 redirect can temporarily route some users to a new page version while keeping the original page intact for others, facilitating real-time comparison and testing.
Load Balancing: During periods of high traffic, a server might use 307 redirects to distribute requests among multiple servers, ensuring the site remains responsive and available.
Temporary Content Relocation: If a content section of a website (like a blog or news page) is being redesigned, a 307 redirect can temporarily send users to an alternate page, allowing access to the content while the main page is under construction.
Geolocation-based Redirection: For sites that have region-specific content or language versions, a 307 redirect can temporarily redirect users to the appropriate regional version based on their location, without changing the original URL's association with the global content.
Conclusion
The 307 Temporary Redirect
status code serves a unique role in the HTTP status code family by ensuring that temporary redirections retain the integrity of the original request. It's particularly valuable when you want to temporarily move a resource without altering the request's nature.
Learn about other codes in 3xx family of HTTP status codes such as 301 Status Code, 304 Status Code and 302 Status Code.
Explore more from Akto
Blog
Be updated about everything related to API Security, new API vulnerabilities, industry news and product updates.
Events
Browse and register for upcoming sessions or catch up on what you missed with exclusive recordings
CVE Database
Find out everything about latest API CVE in popular products
Test Library
Discover and find tests from Akto's 100+ API Security test library. Choose your template or add a new template to start your API Security testing.
Documentation
Check out Akto's product documentation for all information related to features and how to use them.