HTTP location
| HTTP |
| Persistence · Compression · HTTPS |
| Request methods |
| OPTIONS · GET · HEAD · POST · PUT · DELETE · TRACE · CONNECT |
| Header fields |
| Cookie · ETag · Location · Referer |
| DNT · X-Forwarded-For |
| Status codes |
| 301 Moved permanently |
| 302 Found |
| 303 See Other |
| 403 Forbidden |
| 404 Not Found |
The HTTP Location header is returned in responses from an HTTP server under two circumstances:
1. To ask a web browser to load a different web page. It is passed as part of the response by a web server when the requested URI has:
- Moved temporarily, or
- Moved permanently
In this circumstance, the HTTP Location header should be sent with an HTTP status code of 3xx.
2. To provide information about the location of a newly-created resource.
In this circumstance, the HTTP Location header should be sent with an HTTP status code of 201 or 202[1] .
While the internet standard RFC 1945 (HTTP 1.0) requires a complete absolute URI for redirection[2][3], the most popular web browsers support the passing of a Relative URL as the value for a Location: header.[citation needed]
Contents |
[edit] Example
The internet standard requires an absoluteURI token to follow a Location: header, which means it must contain a scheme[4] (e.g., http:, https:, telnet:, mailto:)[5] and conforms to scheme-specific syntax and semantics. For example, the HTTP scheme-specific syntax and semantics for HTTP URLs requires a "host" (web server address) and "absolute path", with optional components of "port" and "query". In the case that there is no absolute path present, it must be given as "/" when used as a Request-URI for a resource.[6]
Client request:
GET /index.html HTTP/1.1 Host: www.example.com
Server response:
HTTP/1.1 302 Found Location: http://www.example.org/index.php
[edit] Relative URL Example
This example, while incorrect based on the internet standard[7], will often work in popular browsers.
Client request:
GET /blog HTTP/1.1 Host: www.example.com
Server response:
HTTP/1.1 302 Found Location: /blog/
[edit] References
- ^ Leonard, Richardson (2007). RESTful Web Services. Sebastopol: O'Reilly. pp. 228-230. ISBN 978-0-596-52926-0.
- ^ RFC 2616 (HTTP 1.1)
- ^ RFC 1945 (HTTP 1.0)
- ^ RFC 3305 (URIs, URLs, and URNs)
- ^ IANA Uniform Resource Identifer (URI) Schemes
- ^ RFC 2616 Section 3.2.2 (HTTP URL)
- ^ RFC 2616 Section 14.30 (Location)