What is HTTP 308 Status Code?
The HTTP 308 status code is a permanent redirect response status code. It indicates that the requested resource has been permanently moved to a new URL provided by the Location header. This status code is similar to the HTTP 301 status code, but with the key difference that it maintains the HTTP method and the body of the original request.
Key Points about HTTP 308:
- Permanent Redirection: The resource requested has been permanently moved to the new URL.
- Method Preservation: The original request method (e.g., GET, POST, PUT) and the body are preserved when the client makes the new request to the new URL. This is different from the HTTP 301 status code, where the method may change (e.g., POST to GET).
- Location Header: The new URL is specified in the Location header of the response.
- SEO Friendly: Like HTTP 301, using HTTP 308 for permanent redirection can help with search engine optimization by ensuring search engines update their indexes with the new URL.
Example of an HTTP 308 Response:
HTTP/1.1 308 Permanent Redirect Location: https://new-example.com/resource
In this example, the client is informed that the resource it is trying to access has been permanently moved to https://new-example.com/resource
, and it should use this URL for future requests while keeping the same HTTP method and request body.
What is the Difference Between HTTP 301 and 308 Status Code?
The key difference between HTTP 301 and HTTP 308 status codes is that HTTP 301 may change the HTTP method from POST to GET during redirection, while HTTP 308 preserves the original HTTP method and request body.
HTTP 301 Status Code
-
Permanent Redirect:
- The HTTP 301 status code indicates that the requested resource has been permanently moved to a new URL provided by the Location header.
-
Method Change:
- HTTP 301 redirects may change the HTTP method from POST to GET. This means that if the original request was a POST, the redirected request will be a GET.
-
SEO Friendly:
- HTTP 301 redirects are recognized by search engines as a signal that the URL has permanently moved. This helps in passing the SEO value from the old URL to the new URL.
-
Typical Use Case:
- HTTP 301 is often used when a webpage has been moved to a new location and it is acceptable to convert POST requests to GET requests.
Example:
HTTP/1.1 301 Moved Permanently
Location: https://new-example.com/resource
HTTP 308 Status Code
-
Permanent Redirect:
- The HTTP 308 status code also indicates that the requested resource has been permanently moved to a new URL provided by the Location header.
-
Method Preservation:
- Unlike HTTP 301, HTTP 308 preserves the original HTTP method and the request body. This means that if the original request was a POST, the redirected request will also be a POST with the same body.
-
SEO Friendly:
- HTTP 308 redirects are also recognized by search engines as a signal that the URL has permanently moved, ensuring that the SEO value is passed from the old URL to the new URL.
-
Typical Use Case:
- HTTP 308 is particularly useful for scenarios where it is important to maintain the original HTTP method and request body, such as form submissions or API requests.
Example:
HTTP/1.1 308 Permanent Redirect
Location: https://new-example.com/resource
Key Points of Comparison:
-
Method Handling:
- HTTP 301: May change POST requests to GET.
- HTTP 308: Preserves the original HTTP method (e.g., POST remains POST).
-
Use Case Suitability:
- HTTP 301: Suitable for general permanent redirects where method preservation is not critical.
- HTTP 308: Suitable for permanent redirects where it is crucial to preserve the HTTP method and request body.
-
SEO Implications:
- Both HTTP 301 and HTTP 308 are SEO-friendly and help in passing the link equity and search engine ranking from the old URL to the new URL.
Importance of the HTTP 308 Status Code in SEO
The HTTP 308 status code plays a significant role in SEO (Search Engine Optimization) due to its impact on how search engines handle and index web pages. Here’s why it’s important:
- Permanent Redirection: The HTTP 308 status code indicates a permanent change in the URL of a resource. This tells search engines to replace the original URL with the new URL in their indexes, maintaining the search engine ranking of the original page and transferring link equity to the new URL.
- Preserves HTTP Method and Body: Unlike the HTTP 301 status code, which might change the request method from POST to GET, the HTTP 308 status code preserves the original HTTP method and the request body, which is important for maintaining user experience and the functionality of forms and APIs.
- Maintaining Link Equity: When search engines encounter a 308 redirect, they understand that the original URL's authority and link equity should be passed to the new URL, ensuring backlinks continue to benefit the site's overall SEO.
- Avoiding Duplicate Content: Using a 308 status code helps avoid duplicate content issues, ensuring that only the new URL is indexed, which prevents ranking dilution.
- User Experience: A smooth redirection process ensures that users and search engines do not encounter errors or interruptions, indirectly benefiting SEO by reducing bounce rates and improving engagement metrics.
Example Scenario:
Imagine you have an e-commerce site and you permanently move a product page from /old-product-url
to /new-product-url
. Using a 308 status code in this scenario will:
- Inform search engines that the product has a new permanent URL.
- Preserve the POST method if the redirection involves submitting form data (e.g., user reviews).
- Ensure that any existing backlinks to
/old-product-url
pass their SEO value to/new-product-url
. - Prevent the old URL from being indexed, avoiding duplicate content issues.
How to Use HTTP 308 Status Code for a Website?
Implementing the HTTP 308 status code for permanent redirects on your website involves configuring your web server to respond with a 308 status code and specifying the new URL in the Location header. Here’s how to do it for different web servers:
Apache
.htaccess File:
- Locate the
.htaccess
file in your website’s root directory. If it doesn’t exist, create it. - Add the following lines to set up a permanent redirect:
RewriteEngine On RewriteRule ^old-page$ https://example.com/new-page [R=308,L]
httpd.conf:
- Open your
httpd.conf
file. - Add the following lines to configure a permanent redirect:
Redirect 308 /old-page https://example.com/new-page
Nginx
nginx.conf:
- Open your
nginx.conf
file or the relevant server block configuration file. - Add the following lines to set up a permanent redirect:
server { listen 80; server_name example.com; location /old-page { return 308 https://example.com/new-page; }
IIS (Internet Information Services)
Web.config:
- Locate or create a
web.config
file in your website’s root directory. - Add the following XML configuration to set up a permanent redirect:
<configuration> <system.webServer> <httpRedirect enabled="true" destination="https://example.com/new-page" httpResponseStatus="Permanent" /> </system.webServer> </configuration>
Using PHP
If you prefer to handle redirections within your PHP code:
PHP Script: Add the following code at the top of your PHP file:
<?php
if ($_SERVER['REQUEST_URI'] == '/old-page') {
header("Location: https://example.com/new-page", true, 308);
exit();
}
?>
General Steps
- Identify the Old and New URLs: Determine the URL paths you need to redirect.
- Update Server Configuration: Depending on your server type, use the appropriate method to implement the 308 redirect.
- Test the Redirect: After making the changes, test the redirection by visiting the old URL to ensure it correctly redirects to the new URL with a 308 status code. Use browser developer tools or online HTTP status checkers to verify the status code.
- Update Internal Links: Update any internal links on your website to point directly to the new URL to avoid unnecessary redirects.
- Monitor SEO Impact: Use tools like Google Search Console to monitor how search engines handle the redirection and ensure that the new URL gets indexed properly.
How to Check HTTP 308 Status Code?
Checking for an HTTP 308 status code can be done using various methods, including browser developer tools, command-line tools, and online HTTP status checkers. Here are some of the most common ways to check for an HTTP 308 status code:
Using Browser Developer Tools
Google Chrome:
- Open Chrome and go to the page you want to check.
- Right-click on the page and select "Inspect" or press
Ctrl+Shift+I
. - Go to the "Network" tab.
- Reload the page.
- Look for the request in the list and click on it. Check the "Status" column for the 308 status code and the "Headers" tab for the Location header.
Firefox:
-
Open Firefox and navigate to the desired page.
- Right-click on the page and select "Inspect Element" or press
Ctrl+Shift+I
. - Go to the "Network" tab.
- Reload the page.
- Find the request in the list and click on it. Check the "Status" column and the "Headers" tab for details.
Using Command-Line Tools
cURL:
- Open your terminal or command prompt.
- Use the
curl
command with the-I
option to fetch the headers:curl -I http://example.com/old-page
- Look for the
HTTP/1.1 308 Permanent Redirect
line in the output, indicating the 308 status code, and the Location header for the new URL.
wget:
- Open your terminal or command prompt.
- Use the
wget
command with the--server-response
option:wget --server-response http://example.com/old-pag
- Check the output for the
HTTP/1.1 308 Permanent Redirect
status code and the Location header.
Using Online HTTP Status Checkers
Several online tools can check HTTP status codes and headers. Here are a few:
TechSEOHub Tools:
- Visit HTTP Status Checker.
- Enter the URL you want to check.
- Click on "Check Status."
- The tool will display the status code and headers, including any 308 redirects.
WebConfs HTTP Header Checker:
- Visit WebConfs HTTP Header Checker.
- Enter the URL you want to check.
- Click on "Check Headers."
- Review the results for the 308 status code and the Location header.
Using Programming Languages
Python (using requests library):
- Install the requests library if you haven't already:
pip install request
- Use the following Python script to check the status code:
import requests response = requests.get('http://example.com/old-page', allow_redirects=False) print(response.status_code) print(response.headers['Location']
JavaScript (using Fetch API in a browser console):
-
Open the browser console (F12, then go to the "Console" tab).
- Run the following code:
fetch('http://example.com/old-page', { method: 'GET', redirect: 'manual' }) .then(response => { console.log('Status:', response.status); console.log('Location:', response.headers.get('Location')); });
These methods will help you verify whether a URL is responding with an HTTP 308 status code and where it is redirecting to.
Which HTTP Method is used with HTTP 308 Status Code?
The HTTP 308 status code is used to indicate a permanent redirect, and it is unique in that it preserves the original HTTP method and request body. This means that whatever HTTP method was used in the original request (e.g., GET, POST, PUT, DELETE) will be maintained when the client is redirected to the new URL.
Key Points:
- Method Preservation: Unlike the HTTP 301 status code, which can change the method from POST to GET during the redirection process, the HTTP 308 status code ensures that the original HTTP method is preserved. This is crucial for requests that are not idempotent, such as POST requests, to ensure that the request's intent and data are not altered during the redirection.
- Use Cases: This preservation of the method and request body makes HTTP 308 particularly useful for scenarios where the request contains significant data or when the same type of request needs to be made to a new URL.
What is the Browser Compatibility of HTTP 308 Status Code?
The HTTP 308 status code is generally well-supported across modern browsers, but it's always good to be aware of specific compatibility details to ensure that your web applications behave as expected. Here is an overview of the browser compatibility for the HTTP 308 status code:
Browser Compatibility
-
Google Chrome:
- Supported: Yes
- Version: Supported since Chrome 23
-
Mozilla Firefox:
- Supported: Yes
- Version: Supported since Firefox 26
-
Microsoft Edge:
- Supported: Yes
- Version: Supported since Edge 15
-
Apple Safari:
- Supported: Yes
- Version: Supported since Safari 11
-
Opera:
-
Supported: Yes
- Version: Supported since Opera 15
-
-
Internet Explorer:
- Supported: No
- Notes: Internet Explorer does not support HTTP 308. Users will need to rely on other methods or consider using alternative status codes like 301 or 302 for compatibility with IE.
Detailed Notes:
- Chrome: Full support for HTTP 308 since version 23. It handles the method preservation correctly, ensuring that the original method (e.g., POST) is used after the redirect.
- Firefox: Full support since version 26. Similar to Chrome, it preserves the original request method.
- Edge: Full support since Edge 15. The Edge browser correctly handles HTTP 308 redirects and preserves the request method.
- Safari: Full support since version 11. Safari handles HTTP 308 redirects properly, including method preservation.
- Opera: Opera has supported HTTP 308 since version 15. It correctly preserves the request method during redirection.
- Internet Explorer: Does not support HTTP 308. For IE users, consider using HTTP 301 or 302 if method preservation is not critical, or provide alternative handling through server-side logic or client-side scripting.
Testing Browser Compatibility:
To ensure your application handles HTTP 308 correctly across different browsers:
-
Use Browser Developer Tools:
- Check the Network tab to see how different browsers handle the HTTP 308 status code and verify that the request method and headers are preserved.
-
Use Online Testing Tools:
- Websites like BrowserStack or CrossBrowserTesting can help you test your web application on various browser versions and platforms.
-
Monitor Analytics:
- Use analytics tools to monitor user behavior and identify any issues related to redirects. If you see unexpected patterns or errors, investigate further to ensure compatibility.
Best Practices for Handling HTTP 308
Handling HTTP 308 status codes effectively involves following best practices to ensure smooth redirections, maintain SEO benefits, and provide a consistent user experience. Here are some best practices to follow:
-
Use When Permanent and Method-Preserving Redirects Are Needed:
- Appropriate Use Cases: Employ HTTP 308 for permanent redirections where it’s crucial to preserve the original HTTP method and request body. This is especially important for non-idempotent requests like POST.
-
Set Up Proper Server Configuration:
- Web Server Configuration: Ensure your web server is configured correctly to handle HTTP 308 redirects.
- Apache (.htaccess or httpd.conf):
RewriteEngine On RewriteRule ^old-page$ https://example.com/new-page [R=308,L]
- Nginx (nginx.conf):
server { listen 80; server_name example.com; location /old-page { return 308 https://example.com/new-page; } }
- IIS (Web.config):
<configuration> <system.webServer> <httpRedirect enabled="true" destination="https://example.com/new-page" httpResponseStatus="Permanent" /> </system.webServer> </configuration>
- Apache (.htaccess or httpd.conf):
- Web Server Configuration: Ensure your web server is configured correctly to handle HTTP 308 redirects.
-
Ensure SEO Benefits:
- Update Internal Links: Update all internal links to point directly to the new URL to avoid unnecessary redirects.
- Submit Updated Sitemaps: Submit an updated sitemap to search engines to help them discover the new URLs faster.
- Monitor Search Engine Indexing: Use tools like Google Search Console to monitor how search engines are indexing the new URLs and ensure that the old URLs are removed from the index.
-
Test Thoroughly:
- Verify Redirection: Test the redirection using browser developer tools to ensure it works as expected and the HTTP method and body are preserved.
- Chrome/Firefox Developer Tools: Inspect the Network tab for the 308 status code and Location header.
- Command-Line Tools:
- cURL:
curl -I http://example.com/old-page
- wget:
wget --server-response http://example.com/old-page
- cURL:
- Cross-Browser Testing: Verify the redirect works across all major browsers and versions that your users might use.
- Verify Redirection: Test the redirection using browser developer tools to ensure it works as expected and the HTTP method and body are preserved.
-
Fallback for Unsupported Browsers:
- Internet Explorer Handling: Since Internet Explorer doesn’t support HTTP 308, provide alternative handling for these users. You can use HTTP 301 or 302 for compatibility or use JavaScript to handle redirects in unsupported browsers.
- JavaScript Fallback:
if (navigator.userAgent.indexOf('MSIE') !== -1 || !!document.documentMode) { window.location.href = 'https://example.com/new-page'; }
- JavaScript Fallback:
- Internet Explorer Handling: Since Internet Explorer doesn’t support HTTP 308, provide alternative handling for these users. You can use HTTP 301 or 302 for compatibility or use JavaScript to handle redirects in unsupported browsers.
-
Monitor and Analyze:
- Analytics Monitoring: Use web analytics tools to monitor traffic and ensure that the redirects are functioning correctly. Look for any issues such as increased bounce rates or user drop-offs.
- Server Logs: Regularly check server logs to identify any issues with redirects and ensure they are being processed as expected.
-
User Experience:
- Consistent User Experience: Ensure that users are seamlessly redirected to the new URL without any interruptions or errors. This is particularly important for POST requests where preserving the method and data is critical.
Conclusion
The HTTP 308 status code is a powerful tool for managing permanent redirects while preserving the original request method and body. By correctly implementing and handling HTTP 308 redirects, you can ensure a smooth user experience, maintain SEO benefits, and effectively communicate permanent URL changes to search engines. Proper configuration, thorough testing, and monitoring are key to making sure your redirections work smoothly across all supported browsers. Following these best practices will help you leverage HTTP 308 redirects effectively, enhancing both your site’s performance and user satisfaction.