Location header
The HTTP Location {{Glossary("response header")}}header indicates the URL to redirect a page to.
It only provides a meaning when served with a 3XX redirection response or a {{HTTPStatus("201", "201 Created")}}Created status response.
In redirections, the HTTP method used to make the redirected request to fetch the page pointed to by Location depends on the original method and the kind of redirection:
{{HTTPStatus("303", "303 SeeOther")}}Other responses always result in a{{HTTPMethod("GET")}}GET request in the redirection.{{HTTPStatus("307", "307 TemporaryRedirect")}}Redirect and{{HTTPStatus("308", "308 PermanentRedirect")}}Redirect use the same method as the initiating request.{{HTTPStatus("301", "301 MovedPermanently")}}Permanently and{{HTTPStatus("302", "302Found")}}Found should use the same request method as the initiating request, although this is not guaranteed for older user-agents.
All responses with one of the above status codes include a Location header.
In cases of resource creation, it indicates the URL of the newly-created resource so that a client can make a request for it immediately.
Location and {{HTTPHeader("Content-Location")}}Location are different.
Content-Location indicates the URL to use to directly access the resource in future when content negotiation occurred.
Location is associated with the response, while {{HTTPHeader("Content-Location")}}Location is associated with the representation that was returned.
| Header type |
|---|
Syntax
Location: <url>
Directives
<url>- : May be relative to the request URL or an absolute URL.
Examples
Location: /index.html
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}