HTTP Redirect Complete Guide
Contents
What is an HTTP redirect?
An HTTP redirect (URL redirection) is a mechanism that automatically sends a user from one URL to another. When you request a page, the server may respond with a 3xx status code and a Location header pointing to the new address โ the browser then follows that address automatically.
Redirects are used in many common scenarios:
- Migrating a site to a new domain
- Restructuring URL paths
- Upgrading from HTTP to HTTPS
- Serving different URLs for mobile and desktop
- URL shorteners (bit.ly, t.co, etc.)
- A/B testing and traffic splitting
How redirects work
Client request:
GET /old-page HTTP/1.1
Host: example.com
Server response:
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page
Redirect types explained
301 Moved Permanently
301 is the most common redirect type. It tells clients and search engines that the resource has permanently moved to a new URL.
โ When to use 301
- Permanent domain migration
- Permanent URL restructuring
- HTTP โ HTTPS upgrade
- Consolidating duplicate content
SEO: Search engines transfer link equity (PageRank) to the new URL and update their index. Google typically completes this within a few weeks.
Browser behavior: Browsers may cache 301 redirects, skipping the original URL on future visits.
302 Found (Temporary)
302 signals a temporary move. The original URL remains valid and indexed.
โ When to use 302
- Maintenance pages
- A/B testing
- Geo-based temporary routing
- Short-term mobile/desktop splits
303 See Other
303 forces the client to use GET for the redirected request, regardless of the original method. Primarily used after POST submissions to prevent form resubmission on refresh (the Post/Redirect/Get pattern).
307 Temporary Redirect
307 is like 302 but strictly preserves the original request method. A POST stays a POST after the redirect โ unlike 302, which historically allowed method changes.
308 Permanent Redirect
308 is the method-preserving counterpart to 301. For GET requests, 301 and 308 behave identically. Use 308 when you need a permanent redirect that must not change the request method.
Client-side redirects
Meta refresh
<meta http-equiv="refresh" content="0; url=https://example.com/new-page">
Avoid for SEO โ search engines may not handle it correctly.
JavaScript redirect
window.location.href = "https://example.com/new-page";
Not ideal for SEO since crawlers may not execute JavaScript.
โ ๏ธ Client-side redirect limitations
Client-side redirects don't carry HTTP status codes, so search engines can't determine whether the move is permanent or temporary. Always prefer server-side redirects.
When to use which redirect
- Permanent domain change โ 301
- Temporary maintenance โ 302
- HTTP โ HTTPS โ 301
- www / non-www canonicalization โ 301
- Post form submission โ 303
- A/B test โ 302
- Permanent redirect, preserve method โ 308
- Temporary redirect, preserve method โ 307
SEO impact
Link equity transfer
A 301 redirect passes nearly all link equity to the new URL. Google has stated that 301s transfer close to 100% of PageRank. A 302 does not transfer equity โ the original URL retains its ranking signals.
Index update timeline
After a 301, Google typically:
- Discovers the redirect within days
- Updates the index within 1โ4 weeks
- Fully transfers equity within 1โ3 months
Redirect chain impact
Each additional hop in a chain (A โ B โ C) adds latency and may dilute equity. Google follows up to ~10 hops, but chains longer than 3 are a red flag. Always redirect directly from the original URL to the final destination.
๐ฏ Best practice
Use direct redirects (A โ C). Audit your chains regularly and collapse them whenever possible.
Common problems and fixes
1. Redirect loops
Symptom: Browser shows "too many redirects."
Common causes: CDN/origin HTTPS config conflict, wrong WordPress siteurl, overlapping Nginx/Apache rules, .htaccess misconfiguration.
# Diagnose with curl
curl -I -L https://example.com
Or use 301check.com to visualize the full chain.
2. Query string loss
Make sure your redirect rules preserve query parameters. In Nginx, use $request_uri or $is_args$args.
3. Cached 301s
Browsers cache 301 redirects. If you change a redirect, users may still see the old destination. Test in a private window or clear the cache.
4. Mobile redirect mismatch
If mobile users are redirected to the homepage instead of the equivalent mobile page, fix the URL mapping or switch to a responsive design.
Best practices
- Use 301 for permanent changes, 302 for temporary ones
- When in doubt, start with 302 โ you can always upgrade to 301 once you're sure
- Avoid redirect chains; redirect directly to the final URL
- Preserve query strings in your redirect rules
- Monitor with Google Search Console after major migrations
- Document all redirect rules so the team knows what's in place
- Test with 301check.com before and after any change