HTTP location
   HOME

TheInfoList



OR:

The HTTP Location header field is returned in responses from an
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide We ...
server Server may refer to: Computing *Server (computing), a computer program or a device that provides functionality for other programs or devices, called clients Role * Waiting staff, those who work at a restaurant or a bar attending customers and su ...
under two circumstances: #To ask a web browser to load a different web page (
URL redirection URL redirection, also called URL forwarding, is a World Wide Web technique for making a web page available under more than one URL address. When a web browser attempts to open a URL that has been redirected, a page with a different URL is opened ...
). In this circumstance, the Location header should be sent with an
HTTP status code This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are issued by a server in response to a client's request made to the server. It includes codes from IETF Request for Comments (RFCs), other specification ...
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. 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 URLIETF HTTPbis Working Group Ticket 185
/ref> and, consequently, the updated HTTP 1.1 specifications (IETF RFC 7231) relaxed the original constraint, allowing the use of relative URLs in Location headers.


Examples


Absolute URL example

Absolute URLs are URLs that start with a scheme (e.g., http:, https:, telnet:, mailto:) 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

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


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
:
may get a server response with a path that is absolute because it starts with a slash: HTTP/1.1 302 Found Location: /articles/ The URL of the location is expanded by the client to
.


Relative URL relative path example

A client request for

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
.


See also

*
URL redirection URL redirection, also called URL forwarding, is a World Wide Web technique for making a web page available under more than one URL address. When a web browser attempts to open a URL that has been redirected, a page with a different URL is opened ...
* Post/Redirect/Get


References

{{Reflist Locations