Home / Guides / HTTP redirects explained: 301, 302, 307 and 308
HTTP redirects explained: 301, 302, 307 and 308
A redirect is a server’s way of saying “what you asked for is somewhere else”. Redirects are everywhere: from http to https, from example.com to www.example.com, from an old page to a new one, and from a shortened link to its destination. Used well they are invisible. Used badly they slow pages down, confuse search engines and break forms.
How a redirect works
When your browser requests a page, the server can answer with a 3xx status code and a Location header holding the new address:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/new-page
The browser then makes a second request to the new address. If that one also redirects, you get a chain.
The five status codes
| Code | Name | Permanent? | Keeps the request method? |
|---|---|---|---|
| 301 | Moved Permanently | Yes | Not guaranteed (POST may become GET) |
| 302 | Found | No | Not guaranteed (POST may become GET) |
| 303 | See Other | No | Always switches to GET |
| 307 | Temporary Redirect | No | Yes, same method and body |
| 308 | Permanent Redirect | Yes | Yes, same method and body |
In practice:
- 301 or 308: use these when a page has moved for good. The two are equivalent for page views. 308 is the stricter version, which also keeps a POST as a POST.
- 302 or 307: use these for temporary moves, such as a maintenance page, a short campaign or a login redirect.
- 303: used after a form submission, to send the browser to a result page with a GET request. It prevents a reload from resubmitting the form.
Redirects and SEO
Search engines read the status code as a signal.
- A permanent redirect tells them to replace the old address with the new one in their index, and to pass ranking signals to it.
- A temporary redirect says the old address should stay. If a 302 stays in place for a very long time, search engines may eventually treat it as permanent, but you should not count on that.
- Chains waste crawl time. Googlebot follows up to 10 hops, but every extra hop adds delay and risk. Keep it to one where possible.
- Loops make a page impossible to reach. Browsers stop after about 20 redirects with an error such as “too many redirects”.
The classic mistake is using a 302 for moves that are permanent, such as http to https or www to non-www. Use a 301 or 308.
Redirects and speed
Each redirect costs at least one extra round trip. On a slow mobile connection that can mean several hundred milliseconds per hop. A chain such as:
http://example.com → https://example.com → https://www.example.com → https://www.example.com/home
forces three extra requests before the real page. Combine the rules so that any starting address goes straight to the final one.
HTTP, HTTPS and HSTS
Redirecting http to https is essential, but it has a weak point: the very first request is still sent in clear text, and can be intercepted. The Strict-Transport-Security header (HSTS) tells the browser to go straight to https next time, without making the insecure request. If you see a “307 Internal Redirect” in your browser’s developer tools, that is HSTS at work: the browser performed the redirect itself. Read more in HTTP security headers explained, and check your own headers with the HTTP Security Headers Checker.
A redirect from https back to http is never acceptable, because it drops the encryption.
Common problems
- A redirect chain. Fix it by pointing each old address straight to the final one.
- A redirect loop. Often caused by two rules that disagree, for example one forcing www and another removing it, or a CDN and a server both redirecting to https.
- Redirecting everything to the home page. When you remove a page, redirect it to the closest equivalent page, not to the home page. Search engines treat a blanket redirect to the home page as a “soft 404”.
- Losing the query string or the path. Check that
/old?id=5ends up at/new?id=5if that is what you intend. - Redirects done in JavaScript or with a meta refresh tag. They work for visitors but are weaker signals for search engines, and they are slower. Prefer server redirects.
How to configure redirects
Cloudflare Pages and Netlify (a _redirects file in your published folder):
/old-page /new-page 301
/blog/* /articles/:splat 301
Nginx:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
Apache (with mod_alias and mod_rewrite):
Redirect permanent /old-page https://example.com/new-page
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Many hosting platforms and CDNs also have a settings page for redirect rules, which is easier and less error-prone than editing configuration files.
Check your redirects
Enter any address in the HTTP Redirect Checker. It follows the redirects one by one and shows the status code, the destination and the response time of every hop. It warns about loops, long chains, redirects that drop https, and temporary redirects used where a permanent one is correct.
It is also a safe way to see where a shortened link leads without opening it yourself. If you are examining a link you received, our guide on how to check if a link is safe explains what else to look for.