What is the HTTP 307 Temporary Redirect Status Code & When to Use it?
Table of Contents
Web servers respond to browsers’ requests via HTTP status codes. There are more than 40 server status codes, and 9 of them are explicitly used for URL redirects. Same as all HTTP statuses, redirects status codes consist of three numbers. When it comes to redirects, each code is handled differently, though they may look alike.
Understanding the status codes is essential for the diagnosis and repair of website configuration problems. We’ll cover the ‘307’ HTTP status code in detail, including the importance of the status codes and how they differ.
The 307 redirect allows websites to make changes or updates without disrupting your browsing experience. So, next time you see a 307 error message – don’t worry! It just means that the page you’re looking for has moved, and your browser is following it to the new location.
How HTTP 3XX Redirects work
When you type a web address into your browser, it sends a request to the server hosting the website. The server responds to the HTTP request with the appropriate action indicated by a status code. Sometimes, the server may instruct your browser to look for the content you requested elsewhere. That’s where HTTP 3XX redirection codes come in.
The HTTP 307 status code informs your browser that the requested content is temporarily located in another place. For example, the server may have moved the content to a different URL, but it’s expected to return to the original URL in the future. When your browser receives the HTTP 307 code, it knows to send a new request to the temporary URL where it can get the content from the original resource.
In short, 307 redirections allow servers to temporarily relocate content without losing track of it, so browsers are still able to find it.
Difference between 302 vs 307 for Temporary Redirects
There are different types of HTTP redirects, but two of the most common ones are the 302 and 307 redirects. Both are being used for temporary redirections. The main difference between the two internal redirects is how they handle the request method.
A 302 redirect lets browsers use a different request from the original request. Whereas a 307 redirect requires the same request method for both the original request and the redirect.
This means that with a 302 redirect, visitors may use POST requests on the original page, and they can switch to GET method on the redirected page. On the other hand, a 307 redirect would force them to keep using POST.
Overall, the main takeaway is that if you want to maintain the same request method for future requests, use a 307 redirect. If you want to force the use of another method, use a 302 redirect.
When to Use a 307 Temporary Redirect
The 307 redirect is useful when you need to temporarily move a webpage to a new URL but you plan to move it back to the original URL in the future. For example, you might need to take down a webpage for maintenance. However, you want to redirect visitors to a temporary page that informs them of the maintenance and provides an estimate of when the site will be back online.
Search engines won’t update the new location of the resource in their databases if you use a 307 redirect. Keep in mind that if your site isn’t properly redirected with a permanent redirect, then your link juice won’t pass to the new URL.
How to Set 307 internal redirect?
Setting up a 307 redirect is pretty simple. All you need is access to your website’s server or a content management system (CMS). Ways to set an internal redirect:
- Via the .htaccess file
- Plugins/extensions (if you use WordPress, for example)
307 redirect in .htaccess
First, you’ll need to locate your .htaccess file. It is usually located in the root directory of your website. After that, you must check if the directive “RewriteEngine” is on, as shown in the code block below:
RewriteEngine On
If the code line above is on your .htaccess file, this means that the Apache URL rewriting engine is enabled. After confirming that the rewriting engine is enabled, you can insert this line:
RewriteRule ^example-page\.html$ /new-page.html [R=307,L]
Here is a brief explanation of the code snippet from above:
- “RewriteRule” is a directive, which specifies the redirection rule;
- “example-page.html” is the source URL you want to redirect from;
- “new-page.html” is the URL you want to temporarily redirect to;
- “R=307” indicates that a temporary redirect with status code 307 should be used;
- And the “L” tells Apache to stop processing other rules if this one matches.
SiteGround users can easily edit the .htaccess file and set the redirect from Site Tools > Site > File Manager. Open the root folder of your website, which is yourdomain.com/public_html. Find and select the file .htaccess and press Edit.
Place the redirect code at the top of the file, make the necessary adjustments, and Save the changes.
Plugins
An easier alternative for creating redirects is using plugins for CMS applications such as WordPress. There are tons of useful plugins which let you set redirects quickly and efficiently. A plugin of this sort is the Redirection plugin.
To create a 307 redirect with the Redirection plugin, follow the simple steps below.
- Login to your WordPress Dashboard and install Redirection from Plugins > Add new.
- After activating the plugin, you can find it in the WordPress section Tools > Redirection and complete the initial setup.
- Identify the page or URL that you want to redirect with the plugin.
- Add a new page or create a new post to redirect your visitors to temporarily.
- Open the plugin’s interface in your Dashboard.
- Type the Source URL you want to redirect.
- Type the new destination URL on Target URL.
- Hit the settings button next to Add Redirect to select what type of redirect you want.
- Select the redirect type from the respective dropdown menu.
- Click the Add Redirect button so the plugin can complete the setup.
- Check if the redirect is working using the built-in plugin options under the particular redirect.
Remember that a 307 redirect is temporary, so make sure to remove the redirect once it is no longer needed. This can help avoid confusion for your visitors and improve your website’s overall SEO performance, mainly in terms of link juice.
Overall, you need just a bit of technical know-how to set up 307 redirects effectively and easily.
Summary
To sum up, HTTP 307 is a temporary redirection status code that tells a client to resend the same request to a different URL while maintaining the original method and request body. It is useful when the requested resource has moved to a different location, but the client must continue to use the same method for the new location.
By using 307 redirects, website owners can ensure their visitors are directed to the correct location without losing any important data. It also helps with SEO by ensuring search engines understand that the resource has been temporarily moved rather than permanently deleted.