301 Moved Permanently
The resource has a new permanent address, given in the Location header. Clients should use the new URL from now on.
What 301 means
A 301 tells the client that the URL it asked for has been replaced for good by the one in the Location header. Browsers follow it automatically, and anything that stores links (bookmarks, search engines, API clients with a configured base URL) is expected to switch to the new address.
Two details matter in practice:
- It is cacheable by default. A browser may remember a 301 without any
Cache-Controlheader and go straight to the new URL next time, without asking your server. - The fragment is carried over. If
Locationhas no#fragmentof its own, the browser keeps the one from the original URL.
The POST problem
A client that follows a 301 is allowed to change a POST into a GET, and browsers do. The request body is dropped on the way. For a web page that rarely matters. For a form endpoint, a webhook or an API route it means the redirected request arrives empty, often as a 405 or a confusing validation error.
If the method and body must survive the redirect, use 308 Permanent Redirect, which forbids the change.
When to use it, and when not
Good uses: moving from http:// to https://, choosing between www and the bare domain, renaming a page, changing domain, and settling on one form of a URL (trailing slash or none).
It is the wrong code when:
- the move is temporary or depends on the visitor (language, location, login state, an A/B test): use 302 or 307;
- the content was removed and nothing replaces it: answer 410 or 404 instead of redirecting everything to the home page;
- the endpoint receives POST, PUT or DELETE: use 308.
Setting up a 301
- nginx:
return 301 https://example.com$request_uri;inside theserverorlocationblock for the old address. In arewriterule thepermanentflag does the same. - Apache:
Redirect permanent "/old" "https://example.com/new", orRedirectMatchfor patterns. Without a status keyword,Redirectsends a 302.
Then check the result with curl -I https://example.com/old and read the status line and Location.
- Redirect straight to the final URL. Chains such as http → https → www → trailing slash cost a round trip each, and Googlebot gives up after 10 hops.
- Send each old page to its closest equivalent, not to one catch-all page.
- Update your own internal links so that visitors do not need the redirect at all.
Undoing a 301 that browsers have cached
Because a 301 can be cached without limit, a wrong one is hard to take back: visitors who already received it may not contact the old URL again, so they never see your correction.
- Test with a 302 first and switch to 301 once the target is right.
- While rolling out, add
Cache-Control: max-age=3600to the 301 so that browsers re-check within the hour. - If a bad 301 is already out, the practical fix is to make the wrong destination redirect onward to the right place. You cannot clear other people's caches.
- When testing, trust
curl -Ior a private window over a normal browser tab, which may be replaying its cached redirect.
301 compared with 302, 307 and 308
| Code | Lasts | POST after the redirect | Google treats it as |
|---|---|---|---|
| 301 Moved Permanently | Permanent | May become GET | A strong signal for the target URL |
| 308 Permanent Redirect | Permanent | Stays POST | The same as 301 |
| 302 Found | Temporary | May become GET | A weak signal |
| 307 Temporary Redirect | Temporary | Stays POST | The same as 302 |
Example 301 response
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/pricing/
Content-Type: text/html; charset=utf-8
Content-Length: 57
<a href="https://www.example.com/pricing/">Moved here</a>The short HTML body is a fallback for clients that do not follow redirects automatically. Browsers never show it.
Defined in RFC 9110, section 15.4.2.
Questions
How long do browsers cache a 301 redirect?
There is no fixed limit. A 301 is cacheable by default, so without a Cache-Control header the browser decides for itself and may keep the redirect for a long time. Send Cache-Control: max-age with the 301 if you want a known lifetime.
Does a 301 redirect keep search rankings?
Google follows a 301 and treats it as a strong signal that the target URL is the one to use in place of the old address. A 302 or 307 is followed too, but only counts as a weak signal, so use a permanent redirect for a permanent move.
Should I use 301 or 308?
Use 301 for ordinary pages: every client understands it and search engines treat the two alike. Use 308 when the URL receives POST, PUT or DELETE requests, because a 301 lets the client turn them into a GET and drop the body.
Why did my POST request become a GET after a redirect?
The server answered with a 301 or 302, and clients are allowed to switch to GET when following those. Send the request to the final URL directly, or have the server redirect with 307 or 308, which keep the method and body.