307
Redirection
307 Temporary Redirect: Preserving Method and Body
✦ The Golden Answer: The 307 Temporary Redirect status code is a temporary redirect that guarantees the client will repeat the request using the same HTTP method and request body. Unlike 302 (which may change POST to GET), 307 explicitly preserves the original method. This makes it the correct choice for form submissions, API calls, and any operation where data must not be lost during redirection.
When to Use 307
- POST form submissions – when you need to redirect to a different URL but want to keep the POST data intact.
- PUT or PATCH requests – when updating a resource and the server temporarily moves the endpoint.
- DELETE operations – when the resource is temporarily located elsewhere.
- API redirection – when you need a temporary redirect that doesn't alter the request semantics.
Example: POST Redirect
| Step | Direction | HTTP Message |
|---|---|---|
| 1 | Client → Server | POST /api/orders HTTP/1.1 |
| 2 | Server → Client | HTTP/1.1 307 Temporary Redirect |
| 3 | Client → Server (auto) | POST /api/orders/new HTTP/1.1 |
307 vs. 302 vs. 303
| Status | Permanent? | Method Preservation | Use Case |
|---|---|---|---|
| 302 | ❌ No | May change to GET | Legacy temporary redirect (avoid for POST). |
| 303 | ❌ No | Always GET | After POST to show result (PRG pattern). |
| 307 | ❌ No | ✅ Preserved | Temporary redirect with method/body preservation. |
| 308 | ✅ Yes | ✅ Preserved | Permanent redirect with method/body preservation. |
SEO Implications
- Temporary – search engines do not transfer PageRank for 307 redirects.
- Not for permanent moves – use 308 for permanent moves that preserve method.
- Use for A/B testing – since it's temporary, it's safe for experiments.
When Not to Use 307
- For permanent moves – use 301 or 308.
- When you want to force GET – use 303 (e.g., after form submission to show a result page).
- When you don't care about method preservation – 302 is simpler for GET requests.
Browser and Client Support
307 is well supported by all modern browsers and HTTP libraries. Unlike 302, the behavior is consistent across clients, making it reliable for scenarios where method preservation is critical.
Frequently Asked Questions
Is 307 better than 302?
For POST, PUT, and DELETE requests, yes – 307 guarantees the method and body are preserved, while 302 may change the method to GET. For GET requests, both behave similarly.
Can 307 be cached?
By default, 307 is not cached because it's temporary. You can add Cache-Control headers if you want to cache it for a short period.
What's the difference between 307 and 308?
Both preserve the method and body. 307 is a temporary redirect, while 308 is a permanent redirect. Use 307 for temporary changes and 308 for permanent moves.