Home » How-Tos » For Web Professionals » What is a 307 Status Code and How to Use it?
If you’re a website owner, understanding various HTTP status codes is not just a technicality but a practical necessity. Among the 40+ web server status codes under the HTTP protocol, 9 are specifically designed for URL redirections, each starting with the numeral 3XX and following a unique redirection pattern. Understanding the workings of each redirect code is crucial for resolving website configuration errors and maintaining a smooth online presence.
In this blog, we will explore every aspect of the HTTP 307 status code and explain how it differs from other status codes.
What is HTTP 307 temporary redirect?
You might have encountered the HTTP 307 status code when you were browsing the internet. Think of it as a message from the website server to your browser, saying, “The page you are looking for is at a different location.” Your browser would then send another request to the new location to fetch the page you’re looking for.
The 307 status code is non-disruptive and allows websites to make changes or updates without interrupting the browsing experience. To delve deeper into the 307 status code, let’s first understand how HTTP 3XX status codes operate.
How does the 3xx status code work?
When you enter a web address into your browser, it sends a request to the server that is hosting the website. The server responds with a status code that tells the browser what action to take. Sometimes, the server might direct the browser to retrieve the content from a different location, which is where HTTP 3xx redirection codes come into play.
The HTTP 307 status code, in particular, informs your browser that the content you’re trying to access is temporarily available at a different URL. For instance, the server may have temporarily moved the content to a new location, with the intention of returning it to the original URL later. When your browser receives the 307 status code, it knows to make a new request to the temporary URL to access the content.
This allows the browser to find the needed content from the original source, even when it’s been temporarily relocated.
Also Read- 301 and 302 Redirects: Understanding Their Differences
What is the difference between 302 vs 307 temporary redirect codes?
HTTP redirects are identified by different status codes, with 302 and 307 being two of the most common for temporary redirects. Both serve to temporarily move a page, but they manage the request method in distinct ways.
A 302 redirect allows the browser to change the request method. For instance, if the original request used a POST method, the redirected request might switch to a GET method. In contrast, a 307 redirect ensures that the request method remains unchanged during the redirect.
In practical terms, with a 302 redirect, a user could start with a POST request on the original page and be redirected to a page where a GET method is used. However, with a 307 redirect, if the original request was made using POST, the redirected request must also use POST.
So, if it’s important to keep the same request method through the redirect, you should choose a 307 redirect. But if you want to allow or enforce a change in the request method, a 302 redirect would be the way to go.
Note: Excessive redirects, also known as redirect chains, can slow down page loading and harm user experience and SEO. It’s best to avoid them. If you need to use a redirect, ensure it’s a 307 redirect only if you’re certain it’s temporary.
When to use 307 redirects?
If you need to temporarily move a webpage to a different URL but plan to bring it back to the original URL later, a 307 redirect can be very helpful. This is particularly useful when you need to take a webpage down for maintenance but still want to send visitors to a temporary page that explains the situation and gives an estimated time for when the site will be back online.
Keep in mind that search engines won’t update their records to reflect the new temporary location if you use a 307 redirect. Additionally, if your site isn’t redirected with a permanent redirect, any link value won’t be passed on to the new URL.
How to Set 307 internal redirect?
Setting up a 307 redirect is quite simple. You just need access to your web server or a content management system (CMS). Here are some ways to set an internal redirect
- Via the .htaccess file
- Plugins/extensions (incase you are using WordPress)
307 redirect in .htaccess
You will have to start by locating your .htaccess file. It is usually in the root directory of your website. Then check if the directive “RewriteEngine” is on, as given below:
RewriteEngine On
If the above code lines reflect on your .htaccess file, that means the rewriting of the Apache URL engine is now enabled. After the confirmation, you can now put this:
RewriteRule ^instance-page . html$ / new-page . html [ R=307 , L]
The code snippet above is explained as follows:
- The “RewriteRule” directive specifies the redirection rule
- “example-page.html” is the source URL to redirect from
- “new-page.html” this is the URL where you need to temporarily redirect
- “R=307” indicates a temporary redirect where you can use the status code 307
- “L” tells Apache to stop processing other rules if this one matches
To edit the .htaccess file and set the redirect in the root directory, go to Site Tools > Site > File Manager. Open your website’s root folder, that is yourdomain.com/public_html. Find and then select the file .htaccess and click Edit.
Place the redirect code at the top of the file, adjust it as necessary, and save the changes.
Using Plugins for Redirect code
Another way to create redirects is to use plugins for CMS applications. Here are the steps to set up a 307 redirect using the WordPress redirection plugin.
- Log in to your WordPress Dashboard and navigate to Plugins > Add New. Search for and install the Redirection plugin.
- Once the plugin is activated, you’ll find it under Tools > Redirection in your WordPress menu. Follow the prompts to complete the initial setup.
- Determine the page or URL you wish to redirect using the plugin.
- Create a new page or post that will serve as a temporary destination for your visitors.
- Access the plugin’s interface through your Dashboard.
- In the Source URL field, enter the URL you want to redirect and the new destination URL in the Target URL field.
- Click the settings icon next to the Add Redirect button to choose the type of redirect you want to implement.
- Choose the appropriate redirect type from the dropdown menu.
- Click the Add Redirect button to finalize the setup.
- Verify that the redirect is functioning correctly using the plugin’s built-in tools.
A 307 redirect is always temporary, so you must remove it once you no longer need it. This way, you can avoid confusion for those visiting your site and also improve the overall SEO performance of your website.
To set up 307 redirects, you just need a bit of technical knowledge.
In a nutshell
URL redirection allows you to use more than one URL for a webpage. It’s best to handle URL redirections on the server with HTTP 3xx redirect status code responses. In case your site is down because of maintenance or other reasons, you can temporarily redirect it to another URL with a 307 Temporary Redirect response.
However, any redirection adds time to your page load. So, use redirections thoughtfully, always considering the user’s experience.