The HTTP Location response header is used to specify the target URL when a page redirect occurs.
The Location response header is used to provide the destination URL when the client receives a HTTP response that includes redirection. The interpretation of the HTTP Location header depends on the HTTP method that was originally used. Several HTTP response status codes will automatically include the HTTP Location header. These include redirection responses, as well as HTTP 201 Created.
The HTTP Location header can specify either a relative or absolute URL.
If the HTTP response is 301 Moved Permanently or 302 Found, then the same HTTP method is to be used for the redirection. However, some older implementations may change the HTTP method.
For HTTP response 303 See Also, the HTTP GET method is used with the new location.
In cases where HTTP responses 307 Temporary Redirect or 308 Permanent Redirect are returned, the same HTTP method used in the original HTTP request will always be used.
When a new resource is created and HTTP status 201 Created is returned, the HTTP Location header will point to the new resource.
There is a difference between the HTTP Location header and HTTP Content-Location header. The former indicates the URL of the newly created resource, whereas Content-Location contains the direct URL that is used during the Content Negotiation phase. Specifically, Location is related to the HTTP response, and Content-Location is related to the entity that was returned to the client.
In the example, the server responds to the HTTP GET request to the origin of example.ai with the 302 Found redirect status code and a new URL in the HTTP Location header for the client to request next:
HTTP/1.1 302 Found Location: https://example.ai/
The HTTP Location header is used to inform the client of where to find the resource either after a redirection or the creation of new content.