跳转到主要内容

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:

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 {{Glossary("[Response header")}}header](https://developer.mozilla.org/en-US/docs/Glossary/Response%20header)

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}}

See also

  • {{HTTPHeader("Content-Location")}}Location
  • Status responses including a Location header: {{HTTPStatus("201")}}201, {{HTTPStatus("301")}}301, {{HTTPStatus("302")}}302, {{HTTPStatus("303")}}303, {{HTTPStatus("307")}}307, {{HTTPStatus("308")}}308.