The Location response header indicates what is the URL to redirect a page too. It has only a meaning when serverd in a 3xx answer.
The HTTP method used to make the new request to fetch the page pointed to by Location depends of the original method and of the kind of redirection. If {{HTTPStatus("303")}} See Also responses always lead to the use of a {{HTTPMethod("GET")}} method, {{HTTPStatus("307")}} Temporary Redirect and {{HTTPStatus("308")}} Permanent Redirect don't change the method used in the original request; {{HTTPStatus("301")}} Permanently Redirect and {{HTTPStatus("302")}} Found doesn't change the method most of the time, though older user-agent may (so you basically don't know). All responss with one of these status code send a Location header.
Beside redirect response, messages with {{HTTPHeader("201")}} Created status also include the Location header. It indicates the URL to the newly created resource.
Location and {{HTTPHeader("Content-Location")}} are different: Location indicates the target of a redirection while {{HTTPHeader("Content-Location")}} indicates, when content negotiation happened, a direct URL to use to access the resource, without the need of further content negotiation.
| Header type | {{Glossary("Response header")}} |
|---|---|
| {{Glossary("Forbidden header name")}} | no |
Syntax
Location: <url>
Directives
- <url>
- A relative (to the request URL) or absolute URL.
Examples
Location: /index.html
Specifications
| Specification | Title |
|---|---|
| {{RFC("7231", "Location", "7.1.2")}} | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content |
Browser compatibility
The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data/README.md and send us a pull request.
{{Compat}}
See also
- {{HTTPHeader("Content-Location")}}
- Status of responses including a
Locationheader: {{HTTPStatus("201")}}, {{HTTPStatus("301")}}, {{HTTPStatus("302")}}, {{HTTPStatus("303")}}, {{HTTPStatus("307")}}, {{HTTPStatus("308")}}.