A 308 Permanent Redirect indicates that a resource has permanently moved to a new URL, and any future requests should be directed to the new location, while preserving the original HTTP method (e.g., GET, POST). "Fixing" a 308 redirect primarily involves ensuring it points to the correct destination URL and is implemented properly on your web server.
Understanding 308 Permanent Redirects
A 308 Permanent Redirect is an HTTP status code that informs browsers and search engines that a page or resource has been permanently moved to a new location. Unlike a 301 redirect, which may change the HTTP method from POST to GET, a 308 redirect explicitly preserves the original request method, making it suitable for scenarios where method preservation is crucial (e.g., form submissions).
Key characteristics:
- Permanent: Indicates the change is not temporary.
- Method Preservation: The client must not change the HTTP method used for the new request.
- SEO Value: Search engines will pass most, if not all, link equity from the old URL to the new one.
Common Reasons to "Fix" a 308 Redirect
You might need to "fix" a 308 redirect if:
- Incorrect Destination: The redirect is pointing to the wrong new URL.
- Redirect Loop: The redirect creates a loop, sending users back and forth between URLs.
- Performance Issues: The redirect chain is too long, or the server configuration is inefficient.
- Changing an Existing Redirect: You want to change an existing 301 redirect to a 308 to ensure method preservation.
How to Implement or Modify (Fix) a 308 Permanent Redirect
The most common and effective way to manage 308 redirects is through server-side configuration files.
1. Server-Side Configuration (Recommended)
This method involves modifying your web server's configuration files (e.g., Nginx or Apache). This is the most robust and SEO-friendly approach.
a. For Nginx:
In Nginx, you can use the return
directive within your server
block. This method is concise and efficient.
-
To redirect a single old page to a new page:
server { listen 80; server_name your-old-domain.com; # Or your current domain if redirecting an internal path location /old-page.html { return 308 http://www.example.com/new-page.html; } # Other server configurations... }
To implement this, you would replace
/old-page.html
with your actual old resource location andhttp://www.example.com/new-page.html
with the new permanent URL location. This is how the redirect looks inside the server block. -
To redirect an entire domain (e.g., from an old domain to a new one):
server { listen 80; listen 443 ssl; server_name old-domain.com www.old-domain.com; return 308 https://www.new-domain.com$request_uri; }
-
To redirect HTTP to HTTPS (308 preserve method):
server { listen 80; server_name www.yourdomain.com yourdomain.com; return 308 https://$host$request_uri; } server { listen 443 ssl; server_name www.yourdomain.com yourdomain.com; # SSL configuration here # root /var/www/html; # index index.html; }
b. For Apache (.htaccess or Virtual Host Configuration):
You can use the Redirect 308
directive or mod_rewrite
rules in your .htaccess
file (if allowed by your server configuration) or directly in your virtual host configuration.
-
To redirect a single old page to a new page (using
Redirect 308
):Redirect 308 /old-page.html http://www.example.com/new-page.html
Similar to Nginx, replace
/old-page.html
with your actual old resource location andhttp://www.example.com/new-page.html
with the new permanent URL. -
To redirect a single old page to a new page (using
mod_rewrite
):RewriteEngine On RewriteRule ^old-page\.html$ http://www.example.com/new-page.html [R=308,L]
-
To redirect an entire domain (e.g., from an old domain to a new one):
RewriteEngine On RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$ [NC] RewriteRule (.*)$ https://www.new-domain.com/$1 [R=308,L]
-
To redirect HTTP to HTTPS (308 preserve method):
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=308,L]
Table: Common 308 Redirect Configurations
Scenario | Nginx Configuration | Apache (.htaccess) Configuration |
---|---|---|
Single Page Redirect | location /old-page.html { return 308 http://www.example.com/new-page.html; } |
Redirect 308 /old-page.html http://www.example.com/new-page.html OR RewriteRule ^old-page\.html$ http://www.example.com/new-page.html [R=308,L] |
Entire Domain Redirect | server { listen 80; server_name old-domain.com www.old-domain.com; return 308 https://www.new-domain.com$request_uri; } |
RewriteEngine On RewriteCond %{HTTP_HOST} ^old-domain\.com$ RewriteRule (.*)$ https://www.new-domain.com/$1 [R=308,L] |
HTTP to HTTPS Redirect | server { listen 80; server_name www.yourdomain.com; return 308 https://$host$request_uri; } |
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=308,L] |
2. Using Programming Languages (Less Common for Permanent URL Changes)
While not ideal for permanent URL changes due to performance and SEO considerations (as the server processes the script before the redirect), you can technically issue a 308 header using server-side scripting languages:
-
PHP:
<?php header("Location: http://www.example.com/new-page.php", true, 308); exit(); ?>
-
Python (Flask example):
from flask import redirect, request @app.route('/old-page') def old_page(): return redirect("http://www.example.com/new-page", code=308)
3. Content Management Systems (CMS)
Many CMS platforms like WordPress offer plugins (e.g., Rank Math, Yoast SEO Premium, Redirection) that allow you to set up 308 redirects without direct server configuration. Check your specific CMS documentation or available plugins for 308 redirect functionality.
Verification and Best Practices
After implementing or modifying a 308 redirect, it's crucial to verify it's working correctly:
- Clear Caches: Clear your browser cache, server cache (if applicable), and any CDN cache.
- Test the Redirect:
- Browser Testing: Open your browser's developer tools (Network tab) and visit the old URL. Check the HTTP status code (should be 308) and the
Location
header. - Online HTTP Header Checkers: Use tools like httpstatus.io or redirect-checker.org to confirm the 308 status code and the correct redirect chain.
- Browser Testing: Open your browser's developer tools (Network tab) and visit the old URL. Check the HTTP status code (should be 308) and the
- Check for Redirect Loops: Ensure the redirect doesn't send the user into an endless loop.
- Monitor Search Console: Keep an eye on your Google Search Console (or equivalent for other search engines) for any crawl errors related to the redirected URLs.
- Update Internal Links: Update all internal links on your website that point to the old URL to directly point to the new 308 redirected URL. This reduces server load and avoids unnecessary redirects.
By following these steps, you can effectively "fix" or correctly implement 308 permanent redirects, ensuring a smooth transition for users and maintaining SEO value.