What is the HTTP 307 Temporary Redirect

The 307 Temporary Redirect status code indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI. Since the redirection can change over time, the client ought to continue using the original effective request URI for future requests.

How HTTP 3xx Redirection Works

HTTP status codes are responses from the server to the browser. Every status code is a three-digit number, and the first digit defines what type of response it is. HTTP 3xx status codes imply a redirection. They command the browser to redirect to a new URL, which is defined in the Location header of the server’s response.

When your browser encounters a redirection request from the server, it needs to understand the nature of this request. The various HTTP 3xx redirect status codes handle these requests. Knowing all of them will help us understand 307 Temporary Redirect and 307 Internal Redirect better.

Understanding the 3xx Status Codes

All HTTP status codes with a 3xx number deal with URL redirection.

How do they work?

When someone tries to access your webpage, their browser forwards a “request” to your site’s server (a system that hosts and delivers web content).

The server responds with a message indicating the page’s status. This message is referred to as an HTTP status code.

If there is a reason for the browser to be guided to a different location, the server sends a 3xx status code.

Here are the 3xx codes in simplified form:

  • 300 multiple choices: The browser can choose between multiple options for the requested page
  • 301 moved permanently: The requested page has a new permanent address
  • 302 found: The requested page has a new address for a short time
  • 303 see other: After an action like submitting a form, the user is sent to another page to prevent duplicate submissions
  • 304 not modified: The requested page hasn’t changed since the user’s last visit, so the browser can use its cached version
  • 307 temporary redirect: The requested page is temporarily at a different address
  • 308 permanent redirect: The requested page has moved permanently

The 302, 303, and 307 codes are temporary redirects. So how are they different?

How to Set Up a 307 Redirect

There are several ways to implement a 307 redirect. The method of choice depends on your site’s platform (e.g., WordPress, Joomla, custom-built), your technical expertise, the tools you’re comfortable with, and your specific goals for the temporary redirect.

1. Editing the .htaccess File

The .htaccess file is a configuration file primarily used by Apache web servers.

This file instructs your server how to respond to various scenarios, including redirects.

You can implement a 307 redirect by modifying this file.

2. Plugins

Does your site use a content management system (CMS) such as WordPress? Then implementing a 307 redirect is easy via a plugin.

Simply search for a redirection plugin in your CMS’s plugin store or on third-party platforms.

Install and activate the plugin. Then follow its instructions.

Let’s take WordPress as an example.

The Redirection plugin is a popular free solution for handling your redirects.

3. Redirects in PHP

PHP is a server-side scripting language commonly used in web development. 

To set up a 307 redirect using PHP, use the “header()” function to send a location header to the browser, instructing it to redirect to a new URL.

Open the PHP file from which you want to redirect.

At the top, before any content, insert:

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

When to Use a 307 Redirect

  1. Site Maintenance
  2. Temporary Content Relocation
  3. Transitioning Between HTTP and HTTPS

When Not to Use a 307 Redirect

  1. For Permanent URL Changes
  2. For Bulk Redirects

What Is HSTS (Strict Transport Security)?

The IETF ratified HTTP Strict Transport Security (HSTS) in 2012 to force browsers to use secure connections when a site is running strictly on HTTPS.

This is akin to Chrome or Firefox saying, “I won’t even try to request this site or any of its resources over the insecure HTTP protocol. Instead, I’ll change it to HTTPS and try again.”

The max-age attribute of the strict-transport-security response header defines how long the browser should follow this pattern. In the example above, this value is set to 3153600 seconds (or 1 year).

Once a site returns this response header, the browser won’t even attempt to make an ordinary HTTP request. Instead, it’ll do a 307 Internal Redirect to HTTPS and try again.

Every time this process repeats, the response headers are reset. Hence, the

HTTP 307 Redirects and SEO

Since a 307 Temporary Redirect response shows that the resource has moved temporarily to a new URL, search engines don’t update their index to include this new URL. The ‘link-juice’ from the original URL is not passed on to the new URL.

This is in contrast to 301 Moved Permanently redirects, wherein search engines update their index to include the new URL and pass on the ‘link-juice’ from the original URL to the new URL.

With a 307 Internal Redirect response, everything happens at the browser level. Hence, it should have no direct effect on your site’s SEO. However, adding your site to an HSTS preload list makes it load faster and be more secure, both of which can help it rank higher in search results.

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.

Facebook
Twitter
LinkedIn
Pinterest
Tumblr