Safeguard
Developer Tools•

301, 302, 303, 307 or 308: choosing the right HTTP redirect

Which redirect status code to use: permanent or temporary, and whether the request method must be kept. A decision table for 301, 302, 303, 307 and 308.

Safeguard Security Team
3 min read

Use 301 or 308 for permanent moves and 302, 303 or 307 for temporary ones. Pick 307 or 308 when the method and body must stay the same, and 303 after a POST so a refresh does not resubmit. The older 301 and 302 leave method handling ambiguous.

The decision table

This table follows MDN's guide to redirections:

CodeNameTypeMethod handling
301Moved PermanentlyPermanentGET unchanged, others may or may not become GET
308Permanent RedirectPermanentMethod and body unchanged
302FoundTemporaryGET unchanged, others may or may not become GET
303See OtherTemporaryOthers change to GET, body lost
307Temporary RedirectTemporaryMethod and body unchanged

MDN explains that the "may or may not" wording for 301 and 302 reflects browser behavior. The specification did not intend method changes, so 308 and 307 were created to remove the ambiguity.

Permanent vs temporary

Permanent redirects tell crawlers to replace the old URL with the new one. Temporary redirects mean the new URL should not be remembered. Use permanent only when you are sure, because clients and caches may keep the mapping a long time. According to the HTTP specification, 301 and 308 are cacheable by default while the temporary codes are not unless the response carries explicit freshness information. Verify this against the current spec for your clients.

Common use cases

  • Redirecting example.com to www.example.com or to a renamed domain.
  • Forcing HTTPS by redirecting http requests to https. Pair this with HSTS, covered in HSTS explained.
  • Keeping old links alive after restructuring a site.
  • Responding 303 after a POST, PUT or DELETE so reloading the page does not resend the request.
  • Pointing a long running request to a status page with 303.

HTTP, HTML and JavaScript redirects

MDN recommends HTTP redirects whenever possible. A meta refresh redirect works when you do not control the server, and a JavaScript redirect only runs on clients that execute scripts. HTTP redirects run first. If HTTP and meta redirects fall out of sync you can get an infinite loop. Each redirect adds a round trip, so keep chains short.

Security notes

Where Safeguard fits

Safeguard does not host or route your site. It scans the dependencies and SBOMs behind your applications, including HTTP client and server libraries, for known issues. You can run a free scan at gold.safeguard.sh/scan.

Quick check

Which redirect keeps a POST as a POST?

307 for temporary and 308 for permanent keep the method and body unchanged.

What is 303 for?

Sending the client to a GET page after a write, so refreshing does not resubmit the request.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.