Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1106521 of Location

  • Revision slug: Web/HTTP/Headers/Location
  • Revision title: Location
  • Revision id: 1106521
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{HTTPSidebar}}

The Location response header indicates the URL to redirect a page to. It only provides a meaning when served with a 3xx status response.

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")}} (Permanent Redirect) and {{HTTPStatus("302")}} (Found) doesn'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.

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 (or the URL of a newly created resource), while {{HTTPHeader("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 {{HTTPHeader("Content-Location")}} is associated with the entity returned.

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

{{Compat}}

See also

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

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong><code>Location</code></strong> response header indicates the URL to redirect a page to. It only provides a meaning when served with a <code>3xx</code> status response.</p>

<p>The HTTP method used to make the new request to fetch the page pointed to by <code>Location</code> depends of the original method and of the kind of redirection:</p>

<ul>
 <li>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;</li>
 <li>{{HTTPStatus("301")}} (Permanent Redirect) and {{HTTPStatus("302")}} (Found) doesn't change the method most of the time, though older user-agents may (so you basically don't know).</li>
</ul>

<p>All responses with one of these status codes send a <code>Location</code> header.</p>

<p>Beside redirect response, messages with {{HTTPHeader("201")}} (Created) status also include the <code>Location</code> header. It indicates the URL to the newly created resource.</p>

<p><code>Location</code> and {{HTTPHeader("Content-Location")}} are different: <code>Location</code> indicates the target of a redirection (or the URL of a newly created resource), while {{HTTPHeader("Content-Location")}} indicates the direct URL to use to access the resource when <a href="/en-US/docs/Web/HTTP/Content_negotiation">content negotiation</a> happened, without the need of further content negotiation. <code>Location</code> is a header associated with the response, while {{HTTPHeader("Content-Location")}} is associated with the entity returned.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Response header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>no</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
Location: &lt;url&gt;
</pre>

<h2 id="Directives">Directives</h2>

<dl>
 <dt>&lt;url&gt;</dt>
 <dd>A relative (to the request URL) or absolute URL.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre>
Location: /index.html</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Title</th>
  </tr>
  <tr>
   <td>{{RFC("7231", "Location", "7.1.2")}}</td>
   <td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data/README.md">https://github.com/mdn/browser-compat-data/README.md</a> and send us a pull request.</p>

<p>{{Compat}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{HTTPHeader("Content-Location")}}</li>
 <li>Status of responses including a <code>Location</code> header: {{HTTPStatus("201")}}, {{HTTPStatus("301")}}, {{HTTPStatus("302")}}, {{HTTPStatus("303")}}, {{HTTPStatus("307")}}, {{HTTPStatus("308")}}.</li>
</ul>
Revert to this revision