← Back to Chapters

307 Temporary Redirect

? 307 Temporary Redirect

? Quick Overview

HTTP status code 307 Temporary Redirect tells the client that the requested resource has been temporarily moved to another URL, and the request method and body must remain unchanged.

? Key Concepts

  • Indicates a temporary redirection
  • Preserves the original HTTP method (GET, POST, PUT)
  • Preserves the request body
  • Client should continue using the original URL for future requests

? Syntax / Theory

When a server responds with 307, it includes a Location header pointing to the new temporary URL. Unlike 302, the HTTP method must not change.

? Code Example(s)

? View Code Example
// Example of an HTTP 307 response header
HTTP/1.1 307 Temporary Redirect
Location: https://example.com/new-endpoint
? View Code Example
// Node.js Express example sending a 307 redirect
res.redirect(307, "/temporary-path");

? Live Output / Explanation

What Happens?

The browser or client automatically sends the same request (method + data) to the URL provided in the Location header.

? Interactive Example / Diagram

Click the button below to visualize how a 307 redirect preserves the method (POST) and body data.

Client (Browser)
Payload: { "user": "alice" }
 
Old Server /old-api
Moved Temporarily
 
New Server /new-api
Ready
> Ready to start...

? Use Cases

  • Temporary API version routing
  • Load balancing without breaking POST requests
  • Maintenance-mode routing
  • Authentication gateways

✅ Tips & Best Practices

  • Use 307 instead of 302 when request method must not change
  • Always include a valid Location header
  • Avoid using for permanent URL changes

? Try It Yourself

  • Create an Express route that redirects POST requests using 307
  • Test behavior with curl or Postman
  • Compare 301, 302, and 307 responses