You're finalizing a large purchase online. You fill in your credit card details, click the "Pay Now" button, and for a brief moment, your browser sends a POST
request with all your sensitive data. Suddenly, the server needs to redirect you to a 3D Secure authentication page. What happens to that original POST
request with your payment information? Does it get lost? Is it sent incorrectly?
This critical scenario is where the subtle differences between HTTP redirect codes become massively important. It's the specific job of one of the most precise and valuable status codes: 307 Temporary Redirect
.
While its cousin 302 Found
is a well-known "temporary redirect," 307
is its stricter, more reliable sibling. It was created to solve a crucial ambiguity in the original HTTP specification, ensuring that sensitive operations like payments and form submissions aren't handled incorrectly during a redirect.
It's the difference between a vague instruction like "Go over there" and a precise command like "Take everything you were going to give me and give it to that other person instead."
If you're a developer building robust web applications, especially with APIs that handle payments, logins, or data submissions, understanding 307
is essential.
And before we dive into the technical details, if you're building or testing APIs that involve complex redirect flows, you need a tool that can handle these nuances. Download Apidog for free; it's an all-in-one API platform that allows you to easily test different redirect types, verify that request methods are preserved, and ensure your application's critical pathways are secure and reliable.
Now, let's roll up our sleeves and explore everything about status code 307 Temporary Redirect.
The Problem: The Ambiguity of the 302 Redirect
To understand 307
, we must first understand the flaw it was designed to fix. The story begins with the original temporary redirect, 302 Found
.
The HTTP/1.0 specification for 302
was ambiguous. It stated that the client should perform the redirect, but it didn't explicitly say whether the redirected request should use the same HTTP method (e.g., POST
, PUT
) as the original request.
This led to a problem: for safety reasons, most browser vendors implemented 302
by changing the method of the redirected request to GET. This made sense for most basic web browsing but caused disasters for programmatic or API-driven interactions.
The Disaster Scenario:
- A client
POST
s form data to/submit-payment
. - The server responds with
302 Found
and aLocation: /confirm
header. - The browser follows the redirect by sending a GET request to
/confirm
. - The sensitive
POST
data is lost. The/confirm
endpoint, expecting aGET
, might show a page but has no idea what payment to confirm.
The 307
status code was introduced in HTTP/1.1 to eliminate this dangerous ambiguity once and for all.
What Does HTTP 307 Temporary Redirect Actually Mean?
The 307 Temporary Redirect
status code is a clear, unambiguous instruction. It indicates that the target resource resides temporarily under a different URI, and the user agent MUST NOT change the request method used in the original request when it makes the redirected request.
If the original request was a POST
, the redirected request must be a POST
. If it was a PUT
, it must remain a PUT
. The method and body must be identical.
A typical 307
response looks like this:
HTTP/1.1 307 Temporary RedirectLocation: <https://auth.example.com/3d-secureContent-Type:> text/htmlContent-Length: 125
<html><head><title>307 Temporary Redirect</title></head><body><center><h1>307 Temporary Redirect</h1></center></body></html>
The key, as with all redirects, is the Location: <https://auth.example.com/3d-secure
> header. The magic is in the semantic guarantee of the 307
status code itself.
Why Do Redirects Exist in HTTP?
Redirects exist to help servers and clients communicate changes in resource availability without breaking the user experience.
Some common scenarios include:
- Website migrations → Moving from
http://
tohttps://
. - Temporary outages → Directing traffic while servers are maintained.
- API versioning → Sending clients to a newer temporary endpoint.
Without redirects, users would be left staring at error messages whenever resources moved.
307 vs. 302: The Critical Difference
This is the most important distinction. The difference is all about method preservation.
Feature | 302 Found |
307 Temporary Redirect |
---|---|---|
Original Spec | Ambiguous on method change. | Explicitly forbids method change. |
Typical Browser Behavior | Changes POST to GET. This is the critical difference. | Preserves the original method (POST remains POST). |
Safety | Unsafe. Should not be used after a non-idempotent request (like POST). | Safe. Designed specifically for non-idempotent requests. |
Analogy | "The information you sent has been received. Now please go to this new page to see the result." (The data is handed off). | "Please resend the exact same package of information to this new address." (The data is redirected). |
When to use which?
- Use
302 Found
when you want to redirect after a POST but the actual data submission is complete, and the redirect is just to show a result page. (Though303 See Other
is often even better for this). - Use
307 Temporary Redirect
when the original request (and its method/body) must be resent to a different URI to complete the action. This is common in authentication flows, payment gateways, and API chains.
How 307 Temporary Redirect Works
Here’s a simplified flow:
1. Client requests a resource:
POST /checkout HTTP/1.1
Host: shop.example.com
2. Server responds with 307 Temporary Redirect:
HTTP/1.1 307 Temporary Redirect
Location: <https://secure.example.com/checkout>
3. Client repeats the POST request at the new location:
POST /checkout HTTP/1.1
Host: secure.example.com
The key point: The request method and body are preserved.
A Real-World Example: The Payment Flow
Let's walk through the payment scenario to see 307
in action.
1. The Original POST: The user submits the payment form. The browser sends:
POST /checkout/payment HTTP/1.1Host: shop.example.comContent-Type: application/x-www-form-urlencoded
card_number=4111...&expiry=12/25&cvc=123
2. The Server's 307 Response: The shop's server needs to hand off to the bank's 3D Secure system. It responds:
HTTP/1.1 307 Temporary RedirectLocation: <https://api.bank.com/3d-secure/authenticate>
3. The Preserved POST: The browser receives the 307
response. Because the spec is unambiguous, it knows it must resend the exact same POST request with the exact same body to the new location.
POST /3d-secure/authenticate HTTP/1.1Host: api.bank.comContent-Type: application/x-www-form-urlencoded
card_number=4111...&expiry=12/25&cvc=123
4. The Final Result: The bank's API receives the payment details directly, performs authentication, and then responds to the client with the next steps (likely a 303
or 302
redirect back to the shop's confirmation page).
This flow ensures no sensitive data is lost between the shop and the bank.
When Should You Use 307 vs 301 or 302?
- 301 Moved Permanently → When the resource location will never change again.
- 302 Found → When the resource is temporarily elsewhere, but method preservation isn’t critical.
- 307 Temporary Redirect → When the resource is temporarily elsewhere, and you must preserve the HTTP method.
Best rule of thumb:
- Use 301 for permanent changes.
- Use 307 for temporary moves that involve sensitive operations (like POST requests).
Benefits of Using 307 Temporary Redirect
- Predictability → The request method is always preserved.
- Security → Prevents accidental method downgrades (e.g., POST turning into GET).
- Developer clarity → Clients know exactly what behavior to expect.
Drawbacks and Common Misconceptions
- Some older clients may not handle 307 correctly.
- Developers sometimes confuse 307 with 302, leading to unintended behavior.
- SEO professionals occasionally misinterpret 307 as equivalent to 301 it’s not.
307 and API Development
In the world of APIs, 307 plays an important role:
- Ensures non-idempotent requests (like POST) remain consistent.
- Helps API gateways safely route traffic during temporary changes.
- Provides a safe way to handle maintenance windows.
Without 307, developers risk clients unintentionally modifying the request type.
Testing 307 Redirects with Apidog

Testing this behavior is crucial. If you're building or testing APIs, you'll likely want to see how your client handles 307 responses. You must ensure that your client correctly handles 307
responses by preserving the method and body. Apidog is the perfect tool for this.
With Apidog, you can:
- Craft a POST Request: Easily set up a POST request with a JSON or form-data body to your endpoint.
- Mock a 307 Response: Configure your server mock in Apidog to return a
307 Temporary Redirect
with aLocation
header. - Observe the Automatic Redirect: Apidog will automatically follow the redirect. The key test is to check the request log for the second request. Did it preserve the POST method? Did it send the exact same body?
- Compare with 302: Run the same test but have your mock return a
302
instead. Observe how Apidog (behaving like a standard browser) changes the method to GET and drops the body. This visual demonstration perfectly illustrates the difference. - Test API Clients: If you're building a programmatic API client (e.g., in Node.js, Python), you can use Apidog to mock the server and ensure your client code correctly handles
307
responses by preserving the method.
This level of testing ensures that critical operations like payments and logins will not break in production. Download Apidog for free and try mocking a 307 response today. It’s a great way to test your applications under real-world redirect conditions.
SEO Implications of 307 Temporary Redirect
From an SEO perspective:
- 307 tells search engines the redirect is temporary.
- Unlike 301, search engines will not transfer link equity (PageRank) to the new URL.
- This is perfect for A/B testing, promotions, or short-term campaigns.
If you use 307 in place of 301, you risk losing long-term SEO benefits.
307 vs. 308 Permanent Redirect
Just as 307
is the strict counterpart to 302
, it has a sibling for permanent moves: 308 Permanent Redirect
.
307 Temporary Redirect
: "Temporarily resend the same request to this other URL."308 Permanent Redirect
: "Permanently resend the same request to this other URL. Update your records."
Use 307
for temporary maintenance, A/B testing, or failover scenarios. Use 308
when you are permanently changing the URL of an endpoint that expects non-GET requests.
Security Considerations With 307
Security-wise, 307 is often safer than 302 because it avoids request manipulation. However, keep in mind:
- Malicious redirects could still lead users to phishing sites.
- Always use HTTPS in the
Location
header to prevent downgrade attacks.
Implementation and Best Practices
- For Server Developers: When you need to temporarily redirect a non-idempotent request (POST, PUT, DELETE), use
307
. It is the safest and most semantically correct choice. - For Client Developers: Ensure your HTTP client library (e.g., Axios, Requests) correctly handles
307
responses by resending the original request to the new location. Most modern libraries do this correctly. - Always Prefer Precision: Default to using
307
over302
when you are certain the method must be preserved. It eliminates ambiguity.
Alternatives to 307 Temporary Redirect
Depending on your use case:
- Use 308 Permanent Redirect if the move is permanent and you need method preservation.
- Use 302 Found if the method doesn’t matter and backward compatibility is more important.
- Use 301 Moved Permanently for permanent relocations where SEO is a priority.
Conclusion: The Guarantee of Safety
The HTTP 307 Temporary Redirect
status code is a testament to the evolution of the web towards greater precision and safety. It solved a critical ambiguity in the protocol that could have led to data loss and security vulnerabilities.
The 307 Temporary Redirect status code is more than just another number in the HTTP specification. It solves real-world problems by making sure that request methods and bodies stay intact during redirects.
While 302
and 303
have their places, the 307
provides a crucial guarantee: that a request will be delivered exactly as intended, even when its destination changes temporarily. This makes it indispensable for building reliable, secure web applications that handle sensitive operations.
Understanding the nuanced differences between these redirect codes is a mark of a senior developer. And when it comes time to test and validate that your applications handle these redirects correctly, a powerful tool like Apidog provides the visibility and control needed to ensure your redirects are not just working, but working precisely.