The HTTP Locationheader field is returned in responses from an HTTPserver under two circumstances:
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
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".
A client requesting
https://www.example.com/index.html
using
A client request for
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:[7]
HTTP/1.1302FoundLocation:2020/zoo
The client removes the path segment after the last slash of the original URL and appends the relative path resulting in
https://www.example.com/blog/2020/zoo.[10][11]