HTTP 301 Moved Permanently says that the resource now lives at another URL for good, and gives that URL in the Location header. It is defined in RFC 9110, section 15.4.2. Browsers follow it automatically, and search engines move their index entry to the new address.
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page/
When to use a 301
- A page or a whole site changed its address, and the old one will not come back.
- You moved from
http://tohttps://, or chose one canonical host (example.comorwww.example.com) for all traffic. - You changed a URL structure and want old links, bookmarks and search results to keep working.
If the move is temporary (a maintenance page, an A/B test, a login detour), use a 302 or 307 instead. Read the comparison on the 302 page.
The caching trap
A 301 is cacheable by default, and browsers keep it for a long time, sometimes until the cache is cleared. This is the source of the most common complaint: you fix the redirect on the server, and your own browser still goes to the old destination. Test redirects with curl -I, which has no cache, or in a private window. If you may need to undo a redirect, send a limited lifetime with it (the cache rules are explained on the 304 page):
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-page/
Cache-Control: max-age=3600
301 against 308
For a GET request the two behave the same. They differ for other methods. With 301, many clients turn a POST into a GET on the second request, and the body is lost. With 308 the method and the body stay. A JSON API that moved to a new URL should answer 308, otherwise clients that send POST will start sending GET without telling anyone.
How to set up a 301
nginx:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
Apache (.htaccess):
Redirect permanent /old-page/ https://example.com/new-page/
Keep $request_uri (or the equivalent) so that the path and query string carry over, and do not redirect everything to the home page.
Common mistakes
- Redirect chains:
http://tohttps://towww, then to a new path, makes three requests where one is enough. Redirect straight to the final address. - Redirect loops: A to B and B to A; browsers stop after about 20 redirects with an error such as
ERR_TOO_MANY_REDIRECTS. - Losing the query string, so that
?id=7is dropped and the new page shows the wrong content. - Using a 301 for something temporary, which then lingers in caches and search results.
- Redirecting every dead URL to the home page. When a page is really gone, a 404 (or 410) is the honest answer; search engines treat a mass redirect to the home page as a soft 404.
To check a redirect target, paste the Location value into the URL parser and read the host, path and query separately. For the other redirect codes, the HTTP status codes tool lists 301, 302, 303, 307 and 308 together.
Frequently asked questions
Does a 301 redirect keep my search ranking?
Google says that it passes ranking signals to the new URL and that 301 and 308 are treated the same way. Keep the redirect for as long as you can, at least a year, and point it at the most relevant page, not always at the home page.
My 301 redirect is stuck in the browser even after I removed it. Why?
Browsers may cache a 301 without any expiry, because the answer is 'permanent'. Clear the site's cache or test in a private window. When you are not sure that a redirect is final, use a 302 or 307, or send Cache-Control with a short max-age.
What is the difference between 301 and 308?
Both are permanent. With 301, a client may change a POST into a GET when it follows the redirect, for historical reasons. 308 forbids that: the method and the body are repeated at the new URL. Use 308 for API endpoints that moved.
Can a Location header be a relative path?
Yes. RFC 9110 allows a relative reference such as /new-page/ in Location, and clients resolve it against the request URL. An absolute URL is still clearer in logs, and is the safer choice when a proxy sits in front.
More in this reference
- HTTP 302 Found: temporary redirects, and when to use 303 or 307 instead
- HTTP 304 Not Modified: how conditional requests and ETags save bandwidth
- HTTP 400 Bad Request: the common causes and how to find the bad part
- HTTP 401 Unauthorized: missing or invalid credentials, and 401 vs 403
- HTTP 403 Forbidden: why access is refused and how to fix it
- HTTP 404 Not Found: causes, how to debug it and what to return instead
- HTTP 429 Too Many Requests: what it means and how to handle it
- HTTP 500 Internal Server Error: how to find the cause and what to tell users
- HTTP 502 Bad Gateway: finding the broken link between the proxy and the app
- HTTP 503 Service Unavailable: maintenance pages, overload and Retry-After
- HTTP 504 Gateway Timeout: why the proxy gave up waiting, and the timeouts to check