HTTP location

From Wikipedia, the free encyclopedia
Jump to: navigation, search

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 soon-to-be obsolete[2] IETF standard RFC 2616 (HTTP 1.1) requires a complete absolute URI for redirection,[3] the most popular web browsers tolerate the passing of a relative URL as the value for a Location header field.[4] Consequently, the current revision of HTTP/1.1 makes relative URLs conforming.[5]

Examples[edit]

Absolute URL example[edit]

The soon-to-be obsolete IETF standard requires an absolute URI to follow a Location header, which means it must contain a scheme[6] (e.g., http:, https:, telnet:, mailto:)[7] 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.[8]

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[edit]

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

Client request:

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

Server response:

HTTP/1.1 302 Found
Location: /blog/

See also[edit]

References[edit]