307 Temporary Redirect
The resource is temporarily at another URL, and the client must repeat the request there exactly as it was: same method, same body.
What 307 means
A 307 redirects for now, like a 302, with one firm rule added: a client that follows it automatically must not change the request method. A POST is sent again as a POST with the same body, a DELETE stays a DELETE.
The new address is in the Location header. Because the move is temporary, the client should keep using the original URL for later requests. A 307 is not cacheable unless the response says so with Cache-Control or Expires.
When 307 is the right redirect
- An API endpoint is served from somewhere else for a while (another region, a maintenance stand-in) and callers send POST, PUT, PATCH or DELETE.
- An upload has to go to a different host than the one that accepted the request, such as a storage node.
- You are redirecting requests of any method and cannot risk a client rewriting them to GET.
For GET requests, 307 and 302 do the same thing, and either is fine.
When to pick another code
- After a form submission. You want the browser to fetch a result page with GET, not to submit the form a second time to the new URL. That is 303 See Other.
- The move is permanent. Use 308, the permanent counterpart that also keeps the method, or 301 for ordinary pages.
- The target must not receive the body. A 307 to another host hands that host the full request, payload included. Redirect only to hosts you trust with it.
What clients do with a 307
Browsers follow it without asking and resend the body. Other HTTP clients vary, and that is where most 307 problems come from:
- Redirects may be off, or limited to GET. Some libraries do not follow redirects for POST unless told to.
curlneeds-L; with it, a 307 or 308 keeps the method, while a 301 or 302 turns a POST into a GET. - Credentials can be dropped. When a redirect leads to a different host, many clients remove the
Authorizationheader so that it does not leak. The second request then fails with 401.curlonly forwards it with--location-trusted. - A streamed body cannot be replayed. To send the request again the client needs the body a second time. If it was streamed from a pipe or socket, the redirect fails unless the client buffered it.
If you control the client, the sturdy fix for a recurring 307 is to call the final URL directly.
Sending a 307
- nginx:
return 307 https://eu.api.example.com$request_uri; - Apache:
Redirect 307 "/v1/uploads" "https://eu.api.example.com/v1/uploads". There is no keyword for it, so give the number.
Search engines handle a 307 like a 302: Google follows it and counts it as a weak signal, keeping the original URL as the main one.
307 compared with 302, 303 and 308
| Code | Lasts | What happens to a POST |
|---|---|---|
| 307 Temporary Redirect | Temporary | Repeated as POST, with its body |
| 302 Found | Temporary | Usually becomes GET |
| 303 See Other | Temporary | Always becomes GET |
| 308 Permanent Redirect | Permanent | Repeated as POST, with its body |
Example 307 response
HTTP/1.1 307 Temporary Redirect
Location: https://eu.api.example.com/v1/uploads
Content-Length: 0The client now sends the identical request, body included, to the URL in Location, and goes back to the original address next time.
Defined in RFC 9110, section 15.4.8.
Questions
What is the difference between a 307 and a 302 redirect?
Both are temporary. A 307 requires the client to repeat the request with the same method and body. A 302 allows the method to change, and in practice browsers turn a redirected POST into a GET. For GET requests the two behave the same.
Does a 307 redirect resend the POST body?
Yes. The client repeats the whole request at the new URL, including the body. That is the purpose of the code, and also the reason not to use it after a form submission when you only want to show a result page.
Is a 307 redirect cached?
Not by default. It is stored only if the response carries explicit freshness information such as Cache-Control: max-age. Otherwise the client asks the original URL again each time.
Why do I get a 401 after following a 307?
The redirect probably went to a different host, and your HTTP client removed the Authorization header for safety. Call the final host directly, or tell the client explicitly to keep credentials across redirects if you trust the target.