The Short Answer
Use 301 Moved Permanently when the old address will never come back: a domain move, the switch to HTTPS, a page with a new address. Use 302 Found when the old address stays the real one and the redirect is temporary: a maintenance page, a test, a redirect after login.
The Four Redirect Codes
| Code | Lasts | Request method |
|---|---|---|
| 301 | Permanent | May change to GET |
| 302 | Temporary | May change to GET |
| 307 | Temporary | Kept |
| 308 | Permanent | Kept |
For historical reasons, browsers turn a POST into a GET when they follow a 301 or 302, so form data is lost. 307 and 308 were added to forbid that: the client repeats the same method with the same body at the new address. For ordinary page links, which are GET requests anyway, 301 and 308 behave the same.
How Browsers Treat Them
A browser may cache a 301 and go straight to the new address next time without asking the server. If you set a 301 by mistake and remove it, visitors who already saw it can keep being sent away until their cache expires or they clear it. A 302 is not cached unless the response says so. That is why it is safer to test a new redirect as 302 and change it to 301 when you are sure.
How Search Engines Treat Them
- 301 and 308: the new address replaces the old one in search results, and links pointing to the old one count for the new one over time.
- 302 and 307: the old address usually stays in search results, because it is expected to return.
- Choose by intent: if a temporary redirect has become permanent, change it to 301 rather than leaving search engines to guess.
Which One to Use
| Situation | Code |
|---|---|
| New domain | 301 |
| HTTP to HTTPS | 301 or 308 |
| Page renamed | 301 |
| Maintenance page | 302 or 307 |
| Testing a redirect | 302 |
| API endpoint moved | 308 |
Nginx Examples
location = /old-page {
return 301 https://example.com/new-page;
}
location = /sale {
return 302 https://example.com/maintenance.html;
}Check the configuration with sudo nginx -t before reloading. A full HTTPS redirect is shown in Nginx redirect HTTP to HTTPS.
Apache Examples
Redirect 301 /old-page https://example.com/new-page
Redirect 302 /sale https://example.com/maintenance.htmlA Redirect line without a code sends a 302, so always write the number. More patterns are in .htaccess redirect.
Check a Redirect with curl
curl -I http://example.com/old-page
curl -IL http://example.com/old-pageThe first command shows the status and the Location header. -L follows every step, so you can see a chain such as HTTP to HTTPS to www. Keep chains to one step; loops end in ERR_
Common Redirect Mistakes
- Redirecting to the home page: send each old address to its closest new page, not all of them to one place.
- Relative or wrong targets: write the full new address, including
https://, so the result does not depend on how the request arrived. - Losing the path: on a domain move, keep the rest of the address, as
$request_does in Nginx.uri - Internal links left behind: update links on your own pages to the new address, so visitors do not pass through a redirect at all.
The 302 code on its own is covered in 302 Found.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations