Jump to content

HTTP location

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 197.157.231.10 (talk) at 13:13, 4 July 2017 (Google AdSense). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

HTTP URL

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 (URL redirection). 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;
    • Moved permanently; or
    • Processed a request, e.g. a POSTed form, and is providing the result of that request at a different URI
  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]

An obsolete version of the HTTP 1.1 specifications (IETF RFC 2616) required a complete absolute URI for redirection.[2] The IETF HTTP working group found that the most popular web browsers tolerate the passing of a relative URL[3] and, consequently, the updated HTTP 1.1 specifications (IETF RFC 7231) relaxed the original constraint, allowing the use of relative URLs in Location headers.[4]

Examples

Absolute URL example

Absolute URLs are URLs that start with a scheme[5] (e.g., http:, https:, telnet:, mailto:)[6] and conform 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".

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

Relative URLs are URLs that do not include a scheme or a host. In order to be understood they must be combined with the URL of the original request.

Client request for http://www.example.com/blog:

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

Server response:

HTTP/1.1 302 Found
Location: /articles/

The URL of the location is expanded by the client to http://www.example.com/articles/.

See also

References

  1. ^ Richardson, Leonard (2007). RESTful Web Services. Sebastopol: O'Reilly. pp. 228–230. ISBN 978-0-596-52926-0.
  2. ^ "Location". Hypertext Transfer Protocol -- HTTP/1.1. IETF. 1999. sec. 14.30. doi:10.17487/RFC2616. RFC 2616. {{citation}}: Unknown parameter |month= ignored (help)
  3. ^ IETF HTTPbis Working Group Ticket 185
  4. ^ "Location". Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. IETF. 2014. sec. 7.1.2. doi:10.17487/RFC7231. RFC 7231. {{citation}}: Unknown parameter |month= ignored (help)
  5. ^ Uniform Resource Identifier (URI): Generic Syntax. IETF. 2005. doi:10.17487/RFC3986. RFC 3986. {{citation}}: Unknown parameter |month= ignored (help)
  6. ^ "IANA Uniform Resource Identifer (URI) Schemes". Retrieved 2014-11-21.