/ HTTP Status Codes

307 Temporary Redirect

The 307 Temporary Redirect is an HTTP status code that indicates the requested resource has been temporarily moved to a different URI. This status code is used to inform the client that the requested resource is available at a new location, and the client should repeat the request using the provided URI.

When to Use 307 Temporary Redirect

The 307 Temporary Redirect status code should be used when the server wants the client to repeat the request with a different URI, while maintaining the same request method and body. This is particularly useful in cases where the resource has been moved temporarily, and the original URI is expected to be functional again in the near future.

Difference Between 307 Temporary Redirect and 302 Found

While both 307 Temporary Redirect and 302 Found indicate that the requested resource has been temporarily moved to a new location, there is a key difference between the two status codes. The 307 Temporary Redirect status code explicitly requires the client to use the same request method (e.g., GET, POST, PUT) and body when making the request to the new URI. In contrast, the 302 Found status code allows the client to change the request method when making the request to the new URI.

Example of 307 Temporary Redirect

Request

Suppose a client sends a POST request to create a new resource:

POST /api/resource HTTP/1.1
Host: example.com
Content-Type: application/json

{
  "field1": "value1",
  "field2": "value2"
}

Response

The server responds with a 307 Temporary Redirect status code, indicating that the resource has been temporarily moved to a new location:

HTTP/1.1 307 Temporary Redirect
Location: https://example.com/api/temporary-resource

Client Follow-up Request

The client should now repeat the original POST request using the provided URI:

POST /api/temporary-resource HTTP/1.1
Host: example.com
Content-Type: application/json

{
  "field1": "value1",
  "field2": "value2"
}

Handling 307 Temporary Redirect in Browsers

Modern web browsers are designed to handle 307 Temporary Redirect status codes automatically. When a browser receives a 307 Temporary Redirect response, it will automatically repeat the request with the provided URI, using the same request method and body. This ensures a seamless experience for the user, without requiring manual intervention.

Summary

The 307 Temporary Redirect status code is used to inform the client that the requested resource has been temporarily moved to a new location, and the client should repeat the request using the provided URI. This status code is particularly useful in cases where the resource has been moved temporarily, and the original URI is expected to be functional again in the near future.

Was this helpful?

Thanks for your feedback!