HTTP location

{{Short description|Instruction by web server containing the intended location of a web page.}}{{HTTP}}

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:
  2. * Moved temporarily;
  3. * Moved permanently; or
  4. * Processed a request, e.g. a POSTed form, and is providing the result of that request at a different URI
  5. 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.{{cite book|last=Richardson|first=Leonard|title=RESTful Web Services|year=2007|publisher=O'Reilly|location=Sebastopol|isbn=978-0-596-52926-0|pages=[https://archive.org/details/restfulwebservic00rich_0/page/228 228–230]|url-access=registration|url=https://archive.org/details/restfulwebservic00rich_0/page/228}}

An obsolete version of the HTTP 1.1 specifications (IETF RFC 2616) required a complete absolute URI for redirection.{{cite IETF |title=Hypertext Transfer Protocol -- HTTP/1.1 |rfc=2616 |sectionname=Location |section=14.30 |date=June 1999 |publisher=IETF |accessdate= }} The IETF HTTP working group found that the most popular web browsers tolerate the passing of a relative URL[https://web.archive.org/web/20110917055643/http://trac.tools.ietf.org/wg/httpbis/trac/ticket/185 IETF HTTPbis Working Group Ticket 185] and, consequently, the updated HTTP 1.1 specifications (IETF RFC 7231) relaxed the original constraint, allowing the use of relative URLs in Location headers.{{cite IETF |title=Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content |rfc=7231 |sectionname=Location |section=7.1.2 |date=June 2014 |publisher=IETF |accessdate= }}

Examples

= Absolute URL example =

Absolute URLs are URLs that start with a scheme{{cite IETF |title=Uniform Resource Identifier (URI): Generic Syntax |rfc=3986 |date=January 2005 |publisher=IETF }} (e.g., http:, https:, telnet:, mailto:){{cite web |url=https://www.iana.org/assignments/uri-schemes.html |title=IANA Uniform Resource Identifier (URI) Schemes |author= |accessdate=2014-11-21 }} 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".

A client requesting {{mono|https://www.aungmyokyaw.com/index.html}} using

GET /index.html HTTP/1.1

Host: www.example.com

may get the server response

HTTP/1.1 302 Found

Location: https://www.example.org/index.php

{{anchor|Relative_URL_example}}

= Relative URL absolute path 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.

A client request for {{mono|https://www.example.com/blog/all}} may get a server response with a path that is absolute because it starts with a slash:{{cite IETF |title=Uniform Resource Identifier (URI): Generic Syntax |rfc=3986 |sectionname=Relative Reference |section=4.2 |date=January 2005 |publisher=IETF |accessdate=2020-11-22 }}

HTTP/1.1 302 Found

Location: /articles/

The URL of the location is expanded by the client to {{mono|https://www.example.com/articles/}}.{{cite IETF |title=Uniform Resource Identifier (URI): Generic Syntax |rfc=3986 |sectionname=Normal Examples |section=5.4.1 |date=January 2005 |publisher=IETF |accessdate=2020-11-22 }}

= Relative URL relative path example =

A client request for {{mono|https://www.example.com/blog/latest}} may get a server response with a path that is relative because it doesn't start with a slash:

HTTP/1.1 302 Found

Location: 2020/zoo

The client removes the path segment after the last slash of the original URL and appends the relative path resulting in {{mono|https://www.example.com/blog/2020/zoo}}.{{cite IETF |title=Uniform Resource Identifier (URI): Generic Syntax |rfc=3986 |sectionname=Merge Paths |section=5.2.3 |date=January 2005 |publisher=IETF |accessdate=2020-11-22 }}

See also

References

{{Reflist}}

Locations