HTTP 307 Response Status Code Guide: What is it, Usage, Methods

May 20 2024 by Oskay Günaçar

What is HTTP 307 Status Code?

The HTTP 307 status code indicates a "Temporary Redirect." This means that the requested resource has been temporarily moved to a different URI, and the client should use the new URI for future requests.

Unlike the 302 status code, which also indicates a temporary redirect, a 307 status code ensures that the method and the body of the original request are not altered when the new request is made to the new URI.

Example usage: If you try to access http://example.com, and the server responds with a 307 status code and the Location header set to http://new.example.com, the client should make a new request to http://new.example.com using the same method (e.g., GET, POST) and the same request body if applicable.

What is the Difference Between HTTP 302 and 307?

The difference between HTTP 302 and 307 status codes is that while both indicate a temporary redirect, HTTP 302 may cause the client to change the request method to GET whereas HTTP 307 ensures the original method and request body are preserved.

  1. HTTP 302 Found:

    • Originally intended to indicate that a resource is temporarily moved to a different URI.
    • Browsers often interpret a 302 response as a request to redirect using the GET method, regardless of the original method (e.g., POST might be changed to GET).
    • There can be inconsistency in behavior across different browsers and HTTP clients.
  2. HTTP 307 Temporary Redirect:

    • Explicitly indicates that the resource is temporarily located at a different URI.
    • Ensures that the original HTTP method and request body are preserved when redirecting to the new URI.
    • Provides a more consistent and predictable behavior compared to 302, especially for non-GET methods like POST.

Importance of the HTTP 307 Status Code in SEO

The HTTP 307 status code plays an important role in SEO, particularly in preserving the user experience and ensuring accurate tracking of web traffic:

Preservation of Method and Body

Unlike HTTP 302, the HTTP 307 status code ensures that the original HTTP method (e.g., POST) and request body are preserved during the redirect. This is crucial for maintaining the integrity of forms, transactions, and other actions that require specific HTTP methods.

Consistent User Experience

By preserving the method and request body, HTTP 307 ensures that users experience the intended behavior when they are redirected. This consistency helps in avoiding errors or confusion, which can lead to a better user experience and potentially lower bounce rates.

Accurate Traffic Analysis

For SEO, understanding how users navigate through a website is essential. The consistent behavior of HTTP 307 allows for more accurate tracking of user actions and traffic patterns, which is valuable for analyzing user behavior and optimizing website performance.

Temporary Nature

Since HTTP 307 indicates a temporary redirect, search engines understand that the original URL will be used again in the future. This helps search engines to retain the original URL in their index, preserving its ranking and relevance, unlike a permanent redirect (HTTP 301) which would transfer the ranking to the new URL.

Avoiding Duplicate Content

Proper use of temporary redirects like HTTP 307 can help prevent issues with duplicate content. When the redirect is temporary, search engines know not to index the new URL as a separate page, thus avoiding potential duplicate content penalties.

In summary, the HTTP 307 status code is important for SEO because it ensures method and body preservation during redirects, maintains a consistent user experience, allows for accurate traffic analysis, indicates the temporary nature of redirects, and helps avoid duplicate content issues.

How to Use HTTP 307 Status Code for a Website?

Using the HTTP 307 status code for a website involves setting up server configurations to handle temporary redirects appropriately. Here’s how you can implement HTTP 307 in different server environments:

Using HTTP 307 in Apache

To set up a temporary redirect with HTTP 307 in Apache, you can modify the .htaccess file or the server configuration file.

.htaccess File

Add the following lines to your .htaccess file:

RewriteEngine On
RewriteRule ^old-page$ /new-page [R=307,L]

Using HTTP 307 in Nginx

To set up a temporary redirect with HTTP 307 in Nginx, you can modify the Nginx configuration file.

Nginx Configuration

Add the following lines to your Nginx configuration file (e.g., nginx.conf or a site-specific configuration file):

server {
    listen 80;
    server_name example.com;

    location /old-page {
        return 307 /new-page;
    }
}

Using HTTP 307 in PHP

To set up a temporary redirect with HTTP 307 in PHP, you can use the header() function.

PHP Script

Add the following lines to your PHP script:

<?php
header("Location: /new-page", true, 307);
exit();

Using HTTP 307 in Node.js

To set up a temporary redirect with HTTP 307 in Node.js using the Express framework, you can use the res.redirect() method with the status code.

Node.js (Express)

Add the following lines to your Express route handler:

const express = require('express');
const app = express();

app.get('/old-page', (req, res) => {
    res.redirect(307, '/new-page');
});

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

Using HTTP 307 in ASP.NET

To set up a temporary redirect with HTTP 307 in ASP.NET, you can use the Response.Redirect method with the appropriate status code.

ASP.NET (C#)

Add the following lines to your ASP.NET controller:

public ActionResult OldPage()
{
    return Redirect("/new-page", permanent: false);
}

By using the HTTP 307 status code correctly in your server or application configuration, you can ensure that temporary redirects preserve the original HTTP method and request body, which is particularly important for forms and other non-GET requests. This helps maintain a consistent user experience and accurate traffic tracking.

How to Check HTTP 307 Status Code?

To check if an HTTP 307 status code is being correctly returned by your server, you can use several methods, including browser developer tools, cURL, and online tools. Here’s how you can do it:

Using Browser Developer Tools

Google Chrome

  1. Open the web page in Google Chrome.
  2. Right-click on the page and select "Inspect" to open Developer Tools.
  3. Go to the "Network" tab.
  4. Refresh the page (F5).
  5. Look for the request to the old URL in the list of network requests.
  6. Click on the request, and check the "Headers" tab for the status code. You should see "307" under the "Status Code" field.

Mozilla Firefox

  1. Open the web page in Mozilla Firefox.
  2. Right-click on the page and select "Inspect Element" to open Developer Tools.
  3. Go to the "Network" tab.
  4. Refresh the page (F5).
  5. Look for the request to the old URL in the list of network requests.
  6. Click on the request, and check the "Headers" section for the status code. You should see "307 Temporary Redirect" under the "Status" field.

Using cURL Command

You can use the curl command in the terminal or command prompt to check the status code of a request.

curl -I -L http://example.com/old-pag

The -I option fetches the headers only, and the -L option follows redirects. Look for the "HTTP/1.1 307 Temporary Redirect" line in the output.

Using Online Tools

There are several online tools available that allow you to check the HTTP status code of a URL. Some popular ones include:

HTTP Status Code Checker

  1. Go to an online HTTP status code checker tool (e.g., TechSEOHub's HTTP Status Checker).
  2. Enter the URL you want to check.
  3. Click the "Check Status" button.
  4. The tool will display the HTTP status code, including any 307 redirects.

Redirect Checker

  1. Go to an online redirect checker tool (e.g. TechSEOHub's HTTP Redirect Checker).
  2. Enter the URL you want to check.
  3. Click the "Check" button.
  4. The tool will display the HTTP status code for each step of the redirection chain.

Using Python Requests Library

If you prefer to check programmatically, you can use the requests library in Python.

import requests

response = requests.get('http://example.com/old-page', allow_redirects=False)
print(response.status_code)  # Should print 307

By using these methods, you can verify whether your server is correctly returning the HTTP 307 status code for temporary redirects.

Which HTTP Method is used with HTTP 307 Status Code?

The HTTP 307 status code is used to indicate that the requested resource has been temporarily moved to a different URI. Importantly, it ensures that the original HTTP method and request body are preserved when redirecting to the new URI. This means that whatever HTTP method was used in the original request (e.g., GET, POST, PUT, DELETE) will also be used for the redirected request.

Key Points:

  • Preserves the HTTP Method: The original HTTP method is maintained in the redirect. For example, if the original request was a POST request, the redirected request will also be a POST request.
  • Preserves the Request Body: Any data included in the body of the original request will be sent in the body of the redirected request.

Example Scenario:

  1. Original Request: A client sends a POST request to http://example.com/submit-form.
  2. Server Response: The server responds with a 307 status code and a Location header pointing to http://example.com/new-form-location.
  3. Redirected Request: The client automatically resends the POST request, including the original request body, to http://example.com/new-form-location.

Example Using cURL:

If you want to see this in action using cURL:

curl -X POST -d "param1=value1&param2=value2" -I -L http://example.com/old-form-location

In this example, -X POST specifies the HTTP method, and -d "param1=value1&param2=value2" specifies the request body data. The -L option follows the redirect, and the original method and body are preserved.

Summary

The HTTP 307 status code is particularly useful when you want to temporarily redirect requests while ensuring that the original HTTP method and request body are preserved. This is especially important for methods like POST, PUT, or DELETE, where the method and body of the request are crucial to the operation being performed.

What is the Browser Compatibility of HTTP 307 Status Code?

The HTTP 307 status code is widely supported by modern web browsers. Here is an overview of the compatibility across major browsers:

Browser Compatibility

Google Chrome

  • Version Support: Supported from early versions.
  • Notes: Handles 307 redirects correctly by preserving the original HTTP method and request body.

Mozilla Firefox

  • Version Support: Supported from early versions.
  • Notes: Properly implements 307 redirects, maintaining the original request method and body.

Microsoft Edge

  • Version Support: Supported from early versions.
  • Notes: Fully supports 307 redirects with method and body preservation.

Safari

  • Version Support: Supported from early versions.
  • Notes: Correctly preserves the original HTTP method and body during 307 redirects.

Opera

  • Version Support: Supported from early versions.
  • Notes: Implements 307 redirects as expected, maintaining the original request method and body.

Best Practices for Handling HTTP 307

When implementing HTTP 307 redirects, it's important to follow best practices to ensure a smooth and consistent user experience while maintaining the integrity of the original requests. Here are some best practices for handling HTTP 307:

1. Preserve the Original HTTP Method and Body

The primary advantage of using HTTP 307 is its ability to preserve the original HTTP method and body during the redirect. Ensure your server and application logic are designed to handle this correctly.

2. Use for Temporary Redirects Only

Use HTTP 307 only for temporary redirects. If the change is permanent, use HTTP 301 (Moved Permanently) instead. This helps both users and search engines understand the nature of the redirect.

3. Provide Clear and Accurate Location Header

Ensure that the Location header in your HTTP 307 response points to the correct temporary URL. The Location header must be a valid and complete URL.

HTTP/1.1 307 Temporary Redirect
Location: http://example.com/new-location

4. Maintain Consistency Across Redirects

Ensure that the server-side logic is consistent in how it handles redirects. Inconsistent handling can lead to unpredictable behavior and potentially broken flows, especially for non-GET methods.

5. Test Across Different Scenarios

Test the redirects in various scenarios to ensure they work as expected. This includes testing with different HTTP methods (GET, POST, PUT, DELETE) and different types of request bodies (form data, JSON, XML).

6. Monitor Redirect Performance

Keep an eye on the performance of your redirects. Excessive use of redirects can impact load times and user experience. Tools like Google Analytics and server logs can help monitor and analyze redirect performance.

7. Update Documentation and Communicate Changes

If you are making changes that involve HTTP 307 redirects, update your documentation accordingly and communicate these changes to your team and users. Clear documentation helps in maintaining consistency and understanding the redirect logic.

8. Ensure Proper SSL/TLS Configuration

If your redirects involve moving from HTTP to HTTPS or vice versa, ensure that SSL/TLS certificates

Conclusion

The HTTP 307 status code, known as "Temporary Redirect," is a valuable tool for managing temporary URL changes while preserving the original HTTP method and request body. This is particularly important for maintaining the integrity of web transactions and ensuring a consistent user experience. By understanding and implementing best practices for handling HTTP 307, such as preserving the original request method, providing accurate Location headers, and testing across different scenarios, you can ensure that your website's temporary redirects are both effective and SEO-friendly. Additionally, the broad browser compatibility of HTTP 307 makes it a reliable choice for managing temporary URL redirections across various platforms. Proper use of HTTP 307 helps maintain the user experience, improve traffic analysis accuracy, and prevent issues with duplicate content, making it an essential tool for web developers and SEO professionals alike.

Oskay Günaçar
Oskay Günaçar is a Technical SEO expert and backend developer. His main areas of interest are back-end programming, Python, Django, Go, semantic SEO, technical SEO. With more than 5 years of SEO experience, he has held SEO specialist positions at İkiler, Webtures, Boosmart, and Storyly.io companies, and has been involved in numerous projects as an outsourced expert. Through the TechSEOHub website, he aims to share the expertise and experience he has gained from managing and developing (SEO) processes for many successful and large websites in the industry, and to produce content for easy access to accurate and high-quality information.