Use a 301 redirect when a page has moved permanently and a 302 when the move is temporary. Search engines treat a 301 as a signal to replace the old URL with the new one, while a 302 tells them to keep the original URL. Picking the wrong one rarely breaks a page for visitors, but it can leave the wrong URL in search results.
What each redirect status code means
| Code | Meaning | Typical use |
|---|---|---|
| 301 | Moved Permanently | Site migrations, changed URLs, HTTP to HTTPS, www to non-www |
| 302 | Found (temporary) | Short-term promotions, maintenance pages, A/B tests |
| 307 | Temporary Redirect | Temporary move where the request method must be preserved |
| 308 | Permanent Redirect | Permanent move where the request method must be preserved |
The difference between 301/302 and 307/308 is method handling. Historically, browsers often turned a POST into a GET when following a 301 or 302. The 307 and 308 codes were defined to forbid that, so a POST stays a POST. For ordinary page links this seldom matters. It matters for form submissions and API endpoints that have moved.
When to use a 301 and when to use a 302
Ask one question: will the old URL ever come back? If not, the move is permanent.
- Use 301 or 308 when you change a URL structure, merge two pages, rename a product, move to a new domain, or force HTTPS. You want the new address indexed and the old one retired.
- Use 302 or 307 when the original URL stays the real one. Examples are sending visitors to a seasonal landing page for two weeks, or routing users to a maintenance notice.
Google has said in its documentation that permanent redirects are a strong signal that the target should be the canonical URL, while temporary redirects are a weaker signal for that. It has also stated that redirects in general do not cause a loss of ranking signals in the way many site owners fear, and that it can eventually treat a long-standing 302 like a permanent one. Do not rely on that last behaviour. Using the correct code states your intent clearly and avoids guesswork. Where a redirect is not possible, a canonical tag is a hint rather than an instruction, so redirects remain the stronger tool for moved content.
HTTP to HTTPS and www canonicalization
A site is often reachable at four addresses: http://example.com, http://www.example.com, https://example.com and https://www.example.com. To search engines these are separate URLs. Choose one preferred version and 301 the other three to it, ideally in a single hop each. Linking, sitemaps and canonical tags should all use the preferred form.
Redirect chains and loops
A redirect chain happens when URL A redirects to B, which redirects to C. Each hop costs a full request and response before the browser can even begin loading the real page, which adds delay, especially on mobile connections. Crawlers also follow only a limited number of hops per attempt, so very long chains risk the final page not being reached promptly.
A loop is worse: A redirects to B and B redirects back to A. Browsers stop with a "too many redirects" error and the page cannot be viewed. Loops usually come from conflicting rules, for example one rule forcing HTTPS at the server and another forcing HTTP in an application or CDN setting.
The fix for chains is to point every old URL directly at the final destination. If an old page went A to B in 2021 and B to C this year, update A to redirect straight to C.
How to check a redirect with curl
The -I flag fetches only headers, which is enough to see the status and the Location target:
curl -I http://example.com/old-page
Add -L to follow redirects and print every hop. The output below is an illustrative example of a three-step chain, not a real site:
$ curl -IL http://example.com/old-page
HTTP/1.1 301 Moved Permanently
Location: https://example.com/old-page
HTTP/2 301
location: https://www.example.com/old-page
HTTP/2 301
location: https://www.example.com/new-page
HTTP/2 200
content-type: text/html; charset=UTF-8
Reading it top to bottom: HTTP is upgraded to HTTPS, then the bare domain moves to www, then the old path moves to the new one. Three redirects precede the 200 response. Combining the rules so the first request goes straight to https://www.example.com/new-page would remove two hops. For a visual trace, the redirect checker lists each hop with its status code, and the URL tools help when parameters or encoding complicate a target; see also the URL encoding guide.
Implementation snippets
Apache (.htaccess)
For a single moved page, Redirect is the simplest option:
Redirect 301 /old-page https://www.example.com/new-page
For pattern-based rules or forcing HTTPS, use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
nginx
Inside a server block, return is preferred over rewrite because it is simpler and faster:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
Using $request_uri keeps the path and query string. Test configuration before reloading, and re-run curl afterwards to confirm the result. Browsers cache 301 responses aggressively, so test in a private window or with curl, not just a normal tab.
Common mistakes
- Redirecting everything to the homepage. When a page is removed, send visitors to the closest relevant page. Mass redirects to the homepage are confusing for users, and Google may treat them as soft 404 errors.
- Letting chains grow. Audit old rules whenever you add a new redirect.
- Using 302 for permanent moves. The old URL may remain indexed longer than you want.
- Forgetting internal links and the sitemap. Update navigation, content links and XML sitemap entries to the final URL so your own site does not depend on redirects. A crawl for broken links will also reveal stragglers.
- Removing redirects too soon. Keep them for as long as old URLs still receive links or visits, which in practice often means indefinitely.
Frequently Asked Questions
Does a 301 redirect hurt SEO?
A correctly implemented 301 is the standard way to move content, and Google has said redirects do not by themselves cause ranking loss. Temporary dips after large migrations usually come from other changes, such as broken mappings or missing pages.
How long should I keep a 301 redirect?
Keep it as long as the old URL has inbound links or traffic. Removing it sends those visitors and crawlers to an error page.
Should I use 308 instead of 301?
Both are permanent. Use 308 when the request method must be preserved, such as a moved API endpoint. For normal pages, 301 is universally understood and fine.
How many redirects in a row are too many?
Aim for one hop. Beyond that, each step adds latency, and crawlers and browsers cap how many they will follow.
Comments
Leave a Comment
No comments yet. Be the first to comment!