Redirects are fundamental to web hosting and server management, but choosing the wrong status code can damage your SEO, confuse users, and create caching headaches. The three most common redirect codes—301, 302, and 308—serve different purposes, and understanding when to use each one will save you troubleshooting time and preserve search rankings.
Understanding HTTP Redirect Status Codes
HTTP redirects tell browsers and search engines that a resource has moved. The status code you choose communicates two critical pieces of information: whether the move is permanent or temporary, and how the client should handle the HTTP method on the redirected request.
All three codes—301, 302, and 308—belong to the 3xx family of HTTP status codes. When a server returns one of these codes, it includes a Location header pointing to the new URL. The client then makes a second request to that new location.
The key differences lie in permanence and method handling. Permanent redirects signal to search engines that they should update their index and transfer ranking signals to the new URL. Temporary redirects tell search engines to keep checking the original URL because it might come back.
301 Moved Permanently
A 301 redirect indicates the resource has permanently moved to a new location. This is the most common redirect for production websites and the standard choice for SEO-conscious moves.
When to Use 301
- Migrating your site to a new domain permanently
- Consolidating multiple pages into one canonical URL
- Changing URL structure (e.g., from
/blog.php?id=123to/blog/article-title) - Removing old content that has a suitable replacement
- Enforcing HTTPS or www/non-www preference
SEO Impact
Search engines treat 301 redirects as a signal to transfer most of the original page's ranking power to the new URL. Google and other engines will eventually update their index to replace the old URL with the new one. This process typically takes a few weeks but can vary based on crawl frequency and the authority of your site.
Method Handling Quirk
The 301 status code has a historical quirk: many browsers and HTTP clients will change a POST request to a GET request when following the redirect. If a user submits a form via POST to /old-form, and you return a 301 to /new-form, the browser may follow the redirect as a GET request instead, losing the form data. For most content migrations this doesn't matter, but it's important when redirecting endpoints that accept POST, PUT, or DELETE.
Implementation in Apache .htaccess
# Single URL redirect
Redirect 301 /old-page.html https://example.com/new-page.html
# Redirect entire directory
Redirect 301 /old-directory/ https://example.com/new-directory/
# Pattern-based redirect with mod_rewrite
RewriteEngine On
RewriteRule ^old-blog/(.*)$ /blog/$1 [R=301,L]
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Implementation in Nginx
# Single URL redirect
location = /old-page.html {
return 301 https://example.com/new-page.html;
}
# Pattern-based redirect
location ~ ^/old-blog/(.*)$ {
return 301 /blog/$1;
}
# Force HTTPS
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
302 Found (Temporary Redirect)
A 302 redirect indicates the resource is temporarily available at a different location but may return to the original URL in the future.
When to Use 302
- A/B testing different page versions while preserving the original URL in search results
- Temporary maintenance or promotional pages that will revert
- Geo-targeting redirects based on user location that aren't permanent
- Short-term campaign landing pages
- Server-side redirects for authentication flows
SEO Considerations
Search engines generally do not transfer ranking signals through 302 redirects because the redirect is declared temporary. The original URL stays in the index. However, if a 302 redirect remains in place for an extended period, search engines may start treating it like a 301 and eventually update their index anyway. This behavior is not guaranteed and varies by search engine.
If you intend a permanent move, always use 301. Using 302 for permanent changes will delay or prevent the transfer of SEO value to the new URL.
Method Handling
Like 301, the 302 status code also suffers from the POST-to-GET conversion issue in many clients. This historical behavior stems from early browser implementations that didn't strictly follow the HTTP specification.
Implementation in Apache .htaccess
# Temporary redirect
Redirect 302 /summer-sale https://example.com/promotions/summer
# With mod_rewrite
RewriteEngine On
RewriteRule ^temp-page$ /promo-page [R=302,L]
Implementation in Nginx
location = /summer-sale {
return 302 https://example.com/promotions/summer;
}
308 Permanent Redirect
The 308 status code is a newer addition to the HTTP specification that fixes the method-handling quirk of 301. It guarantees that the request method and body will not change when the redirect is followed.
When to Use 308
- Redirecting API endpoints that accept POST, PUT, PATCH, or DELETE
- Moving form submission endpoints permanently
- Any permanent redirect where preserving the HTTP method is critical
- RESTful API migrations where clients rely on specific HTTP verbs
Method Preservation
If a client sends a POST request with a JSON payload to /api/v1/users, and you return a 308 to /api/v2/users, the client will send another POST request with the same JSON payload to the new URL. This is the primary advantage over 301.
Browser Support and Compatibility
All modern browsers support 308, but older clients may not recognize it. If you're serving a general audience on legacy browsers, 301 is safer for content pages. For API endpoints where you control the client or know it's modern, 308 is the better choice for permanent redirects that preserve methods.
SEO Treatment
Search engines treat 308 the same as 301 for SEO purposes—as a permanent redirect that should transfer ranking signals. The difference is purely in how the HTTP method is handled.
Implementation in Apache .htaccess
# Requires mod_rewrite
RewriteEngine On
RewriteRule ^api/v1/(.*)$ /api/v2/$1 [R=308,L]
Implementation in Nginx
location ~ ^/api/v1/(.*)$ {
return 308 /api/v2/$1;
}
307 Temporary Redirect: The 302 Fix
While not the primary focus here, it's worth mentioning 307, which is the temporary equivalent of 308. Where 302 may convert POST to GET, 307 guarantees the method is preserved for temporary redirects. Use 307 instead of 302 when redirecting API endpoints temporarily or when method preservation matters for a non-permanent redirect.
Implementation in Application Code
For dynamic redirects based on business logic, implement redirects in your application layer.
PHP
// 301 Permanent
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://example.com/new-page');
exit();
// 302 Temporary
header('HTTP/1.1 302 Found');
header('Location: https://example.com/temp-page');
exit();
// 308 Permanent with method preservation
header('HTTP/1.1 308 Permanent Redirect');
header('Location: https://example.com/api/v2/endpoint');
exit();
Node.js (Express)
// 301 Permanent
res.redirect(301, '/new-page');
// 302 Temporary (default)
res.redirect('/temp-page');
// 308 Permanent
res.redirect(308, '/api/v2/endpoint');
Python (Flask)
from flask import redirect, url_for
# 301 Permanent
return redirect(url_for('new_route'), code=301)
# 302 Temporary
return redirect(url_for('temp_route'))
# 308 Permanent
return redirect(url_for('api_v2'), code=308)
Common Redirect Mistakes to Avoid
Redirect chains: Avoid redirecting A → B → C. Each redirect adds latency and risks losing SEO value. Point A directly to C.
Using 302 for permanent moves: This is the most common mistake. If the change is permanent, use 301 or 308. Using 302 delays or prevents SEO transfer.
Forgetting to redirect both www and non-www: If you consolidate on one version, make sure both redirect properly.
Not updating internal links: Redirects should be a safety net, not a permanent solution. Update internal links to point directly to the new URL to reduce server load and improve page speed.
Redirecting to irrelevant pages: A 301 to your homepage is better than a 404, but only slightly. Redirect to the most relevant replacement page when possible.
Testing Your Redirects
Verify redirect behavior before deploying to production.
Using curl
# Follow redirects and show headers
curl -IL https://example.com/old-page
# Show just the first response
curl -I https://example.com/old-page
Look for the status code (301, 302, or 308) and the Location header pointing to the new URL.
Browser Developer Tools
Open your browser's Network tab (F12), navigate to the old URL, and inspect the request. You'll see the status code and the redirect chain if multiple redirects occur.
Online Tools
HTTP header checker tools let you test redirects without command-line access. Enter the URL and review the response headers and status codes.
Redirect Strategy Checklist
- [ ] Determine if the move is permanent or temporary
- [ ] Choose 301/308 for permanent, 302/307 for temporary
- [ ] Use 308/307 for API endpoints or forms where method preservation matters
- [ ] Implement redirects at the server level (.htaccess, Nginx config) when possible
- [ ] Test with curl or browser dev tools before deploying
- [ ] Update internal links to point directly to new URLs
- [ ] Monitor server logs for redirect chains and fix them
- [ ] Check Google Search Console for crawl errors after major redirects
Conclusion
Choosing the right redirect status code is straightforward once you understand the differences. Use 301 for permanent content moves and SEO consolidation. Use 302 for genuinely temporary changes where you expect the original URL to return. Use 308 when you need a permanent redirect that preserves HTTP methods, particularly for APIs. Test your redirects after implementation, avoid redirect chains, and update internal links to minimize the performance cost. Getting redirects right protects your SEO investment and ensures a smooth experience for both users and search engines.
