HTTP 302 Found: temporary redirects, and when to use 303 or 307 instead

Open this example in the tool

Try it in the tool

HTTP Status Codes

Every HTTP status code with its RFC, meaning and when to use it.

cURL to Code

Turn curl commands into fetch, axios, Python requests or Go.

HTTP 302 Found tells the client that the resource is temporarily at another URL, given in Location, and that the original address should be used again next time. It is defined in RFC 9110, section 15.4.3.

HTTP/1.1 302 Found
Location: https://example.com/login?next=/account

The four redirects side by side

Code Permanent? Keeps the method and body? Typical use
301 yes not guaranteed (POST may become GET) a page moved for good
302 no not guaranteed (POST may become GET) a temporary detour, such as sending a visitor to a login page
303 no no, always GET after a form POST, show the result page
307 no yes a temporary redirect for an API call
308 yes yes an API endpoint that moved for good

The HTTP status codes tool shows all of them next to each other when you search for 301, 302, 307, 308.

Where the method changes

When the specification for 302 was first written, it said the client must not change the method. Browsers did it anyway and turned a POST into a GET, and the text was later changed to allow what was already happening. The result is the rule of thumb you need today: a 302 is safe for GET, and unclear for everything else. When a POST must be repeated as a POST, use 307. When you want the browser to do a GET after a form was posted, use 303.

The second case is the Post/Redirect/Get pattern: after POST /orders succeeds, answer 303 See Other with Location: /orders/42. A reload then repeats the harmless GET and does not submit the order twice.

Typical uses of 302

  • Login detours: a protected page redirects to /login?next=... and back afterwards. A browser page can do this; an API should answer 401 instead, because a script cannot follow a login form.
  • Geography or language: the home page sends a visitor to the version for their country.
  • Short links and trackers: they often use a 302 so that the target can change and every click still passes through the service.
  • Testing: an A/B test or a maintenance page that should leave the original URL in place.
  • Defaults of frameworks: Express res.redirect(url), PHP header('Location: ...') and Django redirect() all send 302 unless told otherwise.

Mistakes to avoid

  • A temporary redirect that stays forever. Search engines may decide that it is permanent, but you should say so yourself. Check old 302 rules once in a while and turn them into 301/308.
  • Redirecting a POST API with 302 and wondering why the second request has no body. Use 307 or 308.
  • Open redirects. If Location is built from a query parameter such as ?next=, an attacker can send people to another site from your domain. Allow only paths on your own site, or a fixed list of hosts.
  • Forgetting the query string when you build the new URL.

To reproduce a redirect from a script, convert your curl command with the curl converter, and note which client option follows redirects (it is off by default in several libraries). For a move that will not be undone, read HTTP 301 Moved Permanently.

Frequently asked questions

Is a 302 bad for SEO?

No, when the move really is temporary. Search engines keep the old URL in the index and treat the target as a stand-in. A 302 that stays for months is a sign that you meant a permanent move, and then a 301 or 308 states your intention better.

Why did my POST become a GET after a 302?

For historical reasons most clients change the method to GET when they follow a 302, and drop the body. The standard allows it. If the method must be kept, send 307. If you want a GET on purpose, for example after a form, send 303.

Why do frameworks use 302 by default?

It was the only redirect that old browsers handled in a uniform way, so the habit stayed: res.redirect() in Express, header('Location: ...') in PHP and redirect() in Django all start with 302. Pass the status explicitly when you mean something else.

How can I see a redirect without following it?

curl -I https://example.com/path prints the status line and the Location header and stops there. Add -L only when you want to follow the chain.

More in this reference