301 vs 302: the short answer
Use a 301 when a URL has moved for good, and a 302 when the move is temporary and the original URL will come back. A 301 allows browsers to cache the redirect and tells search engines to show the new URL. A 302 asks for neither, so search results keep the original URL.
Both codes allow a browser to turn a POST request into a GET when it follows the redirect. 307 and 308 exist to forbid that.
Where 307 and 308 fit
For ordinary page links, which use GET, 301 and 308 behave the same, and so do 302 and 307. The difference shows up with POST, PUT and other requests that carry a body.
That makes 308 the right code when moving an API endpoint that accepts POST. A 301 there could turn an order submission into a GET with no body.
- 301 Moved Permanently: permanent. Browsers may switch POST to GET, which drops the request body.
- 302 Found: temporary. Browsers may switch POST to GET.
- 303 See Other: temporary, and the follow-up request is always a GET. Use it to show a result page after a form submission.
- 307 Temporary Redirect: temporary, and the method and body must be sent again unchanged.
- 308 Permanent Redirect: permanent, and the method and body must be sent again unchanged.
How browsers cache permanent redirects
HTTP allows clients to cache a 301 or 308 even when the response has no caching headers, and browsers do. A visitor who once followed a permanent redirect may skip your server on the next visit and go straight to the target.
That makes a mistaken 301 hard to undo. Changing the server rule fixes it for new visitors, but returning visitors keep the cached redirect until it expires or they clear their cache.
Send a Cache-Control header with a modest max-age on permanent redirects you might revise, and test new rules with a 302 before switching to 301. A 302 or 307 is cached only when the response allows it with Cache-Control or Expires.
How search engines treat permanent and temporary redirects
Search engines read the code as a statement about which URL is canonical. Google uses a permanent redirect (301 or 308) as a signal that the target should be the canonical URL, and shows the new URL in results. It doesn't use a temporary redirect (302, 303 or 307) that way, so the source URL stays in results.
The wrong code rarely breaks anything visibly, which is why mistakes last. A site migration done with 302s can leave old URLs in search results. A 301 used for a short campaign can put the campaign page in place of the original in results.
Google's crawlers treat 308 like 301 and 307 like 302, so the method-preserving codes carry the same search signal as their older equivalents.
Which redirect to use
Pick the code by what is true about the move, then check that the redirect reaches the final URL in one hop.
- Moving a page, changing URL structure, switching to HTTPS or moving domains: 301, or 308 if the URLs also receive POST requests.
- Sending visitors elsewhere for a while, such as to a seasonal page or a short promotion: 302, or 307 to keep the method.
- Testing two versions of a page on different URLs: 302. Google's guidance on website testing recommends a temporary redirect so the original URL stays indexed.
- Showing a result page after a form submission: 303, so a refresh doesn't submit the form again.
- Sending signed-out visitors to a login page: 302 or 303, since the original URL remains the real address.
- Planned maintenance: no redirect. Return 503 with a Retry-After header on the original URLs.