Location
Location
The Location
response header indicates the URL to redirect a page to. It only provides a meaning when served with a 3xx
(redirection) or 201
(created) status response.
In cases of redirection, the HTTP method used to make the new request to fetch the page pointed to by Location
depends on the original method and the kind of redirection:
-
303
(See Also) responses always lead to the use of aGET
method. -
307
(Temporary Redirect) and308
(Permanent Redirect) don't change the method used in the original request. -
301
(Moved Permanently) and302
(Found) don't change the method most of the time, though older user-agents may (so you basically don't know).
All responses with one of these status codes send a Location
header.
In cases of resource creation, it indicates the URL to the newly created resource.
Location
and Content-Location
are different. Location
indicates the target of a redirection or the URL of a newly created resource. Content-Location
indicates the direct URL to use to access the resource when content negotiation happened, without the need of further content negotiation. Location
is a header associated with the response, while Content-Location
is associated with the entity returned.
Header type | Response header |
---|---|
Forbidden header name | no |
Syntax
Location: <url>
Directives
- <url>
-
A relative (to the request URL) or absolute URL.
Examples
Location: /index.html
Specifications
Specification |
---|
Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content (HTTP/1.1) # header.location |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
Location |
Yes |
12 |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location