Jump to content

HTTP location

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Rustamabd (talk | contribs) at 16:55, 11 February 2014 (updated link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The HTTP Location header field is returned in responses from an HTTP server under two circumstances:

  1. To ask a web browser to load a different web page. In this circumstance, the Location header should be sent with an HTTP status code of 3xx. It is passed as part of the response by a web server when the requested URI has:
    • Moved temporarily, or
    • Moved permanently
  2. To provide information about the location of a newly created resource. In this circumstance, the Location header should be sent with an HTTP status code of 201 or 202.[1]

While the internet standard RFC 2616 (HTTP 1.1) requires a complete absolute URI for redirection,[2] the most popular web browsers tolerate the passing of a relative URL as the value for a Location header.[citation needed] Consequently, the upcoming revision of HTTP/1.1 will make relative URLs conforming.[3]

Examples

Absolute URL example

The internet standard requires an absolute URI 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

Relative URL example

This example, is incorrect according to the current standard, which specifies the URI returned to be absolute.[7] However, all popular browsers will accept a relative URL[citation needed], and it is correct according to the upcoming revision of HTTP/1.1.[8]

Client request:

GET /blog HTTP/1.1
Host: www.example.com

Server response:

HTTP/1.1 302 Found
Location: /blog/

See also

References

  1. ^ Richardson, Leonard (2007). RESTful Web Services. Sebastopol: O'Reilly. pp. 228–230. ISBN 978-0-596-52926-0.
  2. ^ RFC 2616 (HTTP 1.1)
  3. ^ What are the Consequences for using Relative Location Headers?
  4. ^ RFC 3305 (URIs, URLs, and URNs)
  5. ^ IANA Uniform Resource Identifer (URI) Schemes
  6. ^ RFC 2616 Section 3.2.2 (HTTP URL)
  7. ^ RFC 2616 Section 14.30 (Location)
  8. ^ draft-ietf-httpbis-p2-semantics-26 Section 7.1.2 (Location)