HTTP status code 307 indicates that the requested resource has temporarily moved to a different URI. This status code is similar to 302 “Found,” but 307 emphasizes that the redirection is only temporary, and the client should continue to use the original URI for subsequent requests.
Characteristics of 307 Status Code
-
Temporariness: The temporary movement of the resource is just that—temporary. The client should continue to use the original URI for future requests.
-
Method Preservation: Unlike the 302 status code, the 307 status code explicitly states that the method of the redirected request (such as GET or POST) should not change. If the original request is a POST, the redirected request should also be a POST.
-
Response Header: When returning a 307 status code, the server typically includes a
Location
header specifying the temporary URI.
Common Use Cases for 307 Status Code
-
Temporary Maintenance: When a resource is temporarily unavailable and needs to redirect to a backup page or service.
-
Load Balancing: The server may temporarily redirect requests to a less busy server.
Example Response
HTTP/1.1 307 Temporary Redirect
Location: https://www.example.com/temporary-page/ Content-Length: 0
In this example, the status code 307 indicates that the originally requested resource is temporarily located at https://www.example.com/temporary-page/
. The client (such as a browser) should temporarily redirect to this new URI but continue to use the original URI for future requests.
Note: The 307 status code should not be used for permanent redirection, as it is intended to be temporary. For permanent redirection, the 301 “Moved Permanently” status code should be used.