All articles

HTTP redirects explained: 301, 302, 303, 307 and 308

· 3 min read

A redirect tells the client that the resource is somewhere else, with the new address in the Location header. There are five common redirect codes, and they answer two questions differently:

  1. Is the move permanent or temporary?
  2. Will the client keep the request method (and body), or may it switch to GET?

The quick table

Code Name Permanent Method on redirect
301 Moved Permanently Yes May change POST to GET
302 Found No May change POST to GET
303 See Other No Always GET
307 Temporary Redirect No Preserved
308 Permanent Redirect Yes Preserved

For setup examples and SEO notes on the two most common codes, see the guides to 301 Moved Permanently and 302 Found.

Why 307 and 308 exist

The original specification said clients should not change the method on 301 and 302. Browsers did anyway: they turned a POST into a GET and dropped the body. The behavior became so widespread that RFC 9110 now allows it, and 307 and 308 were added for when the method must be preserved.

  • 301 and 302: browsers keep GET as GET, but a POST usually becomes a GET.
  • 307 and 308: the client repeats the same method with the same body.

For page URLs that are only ever fetched with GET, 301 and 308 behave the same in practice, as do 302 and 307.

Permanent vs temporary

Permanent (301, 308) means "update your links". Browsers cache permanent redirects, often without an expiry, and search engines transfer ranking signals to the new URL and eventually show it instead of the old one.

Temporary (302, 303, 307) means "go there for now, but keep using this URL". Browsers don't cache them by default, and search engines keep the original URL indexed.

Because browsers cache 301s aggressively, a mistaken permanent redirect is hard to undo. Test with a temporary redirect first, then switch.

Which one to use

Situation Code
Moving a page or domain for good 301 or 308
HTTP to HTTPS, or www to bare domain 301 or 308
Renamed API endpoint that accepts POST/PUT 308
Temporarily sending users elsewhere (maintenance, A/B test) 302 or 307
After a form POST, show a result page 303
Login redirect to the page the user wanted 302 or 303
Language or region redirect from / 302 or 307

The POST/redirect/GET pattern

After a successful form submission, respond with 303 to a result page. The browser loads it with GET, so refreshing the page doesn't resubmit the form:

HTTP/1.1 303 See Other
Location: /orders/1042

Examples

nginx

server {
  listen 80;
  server_name example.com www.example.com;
  return 301 https://example.com$request_uri;
}

location = /old-page { return 308 /new-page; }

Apache (.htaccess)

Redirect 301 /old-page /new-page
RedirectMatch 302 ^/sale$ /summer-sale

Express

app.get("/old-page", (req, res) => res.redirect(301, "/new-page"));
app.post("/submit", (req, res) => { /* save */ res.redirect(303, "/thanks"); });

Next.js

// next.config.js
module.exports = {
  async redirects() {
    return [{ source: "/blog/:slug", destination: "/articles/:slug", permanent: true }];
  },
};

Next.js uses 308 for permanent: true and 307 for permanent: false, so form posts keep their method.

How fetch and curl handle redirects

  • fetch follows redirects by default (redirect: "follow"). Use redirect: "manual" to stop, though in browsers you then get an opaque response without the Location header.
  • curl doesn't follow redirects unless you pass -L. Add -I to see just the status and Location:
curl -sIL http://example.com | grep -iE '^(HTTP|location)'

Copying a failing request from DevTools and replaying it like this is often the quickest way to see a redirect loop; see Copy as cURL.

SEO checklist for site moves

  1. Map every old URL to its closest new equivalent; avoid redirecting everything to the homepage.
  2. Use permanent redirects, one hop each, with no chains.
  3. Update internal links, canonical tags, hreflang and the sitemap to the new URLs.
  4. Keep redirects in place for at least a year; longer is better.
  5. Watch crawl errors in Google Search Console after the move.

Shared links keep showing the old preview until platforms re-scrape the page; the Open Graph guide covers refreshing them.

Frequently asked questions

Does a 301 pass SEO value?

Google treats permanent server-side redirects (301 and 308) as a strong signal that the target should be the canonical URL, and temporary redirects as a weak one. Use a permanent redirect when a page has moved for good.

How do I undo a cached 301?

You can't force browsers to forget it. Users must clear their cache, or the old URL must redirect somewhere sensible. Test with 302 before switching to 301 if you're unsure.

Is a meta refresh or JavaScript redirect OK?

Server-side redirects are preferred. Google can follow meta refresh and JavaScript redirects, but they're slower for users and less reliable for other crawlers.

How many redirects in a chain is too many?

Keep it to one hop where possible. Browsers stop after about 20, and Google follows up to 10 hops, but every hop adds latency.

Further reading