Girish Mahajan (Editor)

HTTP location

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

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

Contents

  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.

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

Absolute URL example

Absolute URLs are URLs that start with a scheme (e.g., http:, https:, telnet:,


on Gravtar
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:

Server response:

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:

Server response:

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

References

HTTP location Wikipedia