HTTP location

Last updated

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:
    • 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
  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]

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

GET/index.htmlHTTP/1.1Host:www.example.com

may get the server response

HTTP/1.1302FoundLocation: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
https://www.example.com/blog/all:
may get a server response with a path that is absolute because it starts with a slash: [7]

HTTP/1.1302FoundLocation:/articles/

The URL of the location is expanded by the client to
https://www.example.com/articles/. [8]

Relative URL relative path example

[9]

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

See also

Related Research Articles

<span class="mw-page-title-main">HTTP</span> Application protocol for distributed, collaborative, hypermedia information systems

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 Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser.

The Session Initiation Protocol (SIP) is a signaling protocol used for initiating, maintaining, and terminating communication sessions that include voice, video and messaging applications. SIP is used in Internet telephony, in private IP telephone systems, as well as mobile phone calling over LTE (VoLTE).

A Uniform Resource Identifier (URI) is a unique sequence of characters that identifies a logical or physical resource used by web technologies. URIs may be used to identify anything, including real-world objects, such as people and places, concepts, or information resources such as web pages and books. Some URIs provide a means of locating and retrieving information resources on a network ; these are Uniform Resource Locators (URLs). A URL provides the location of the resource. A URI identifies the resource by name at the specified location or URL. Other URIs provide only a unique name, without a means of locating or retrieving the resource or information about it, these are Uniform Resource Names (URNs). The web technologies that use URIs are not limited to web browsers. URIs are used to identify anything described using the Resource Description Framework (RDF), for example, concepts that are part of an ontology defined using the Web Ontology Language (OWL), and people who are described using the Friend of a Friend vocabulary would each have an individual URI.

<span class="mw-page-title-main">Web server</span> Computer software that distributes web pages

A web server is computer software and underlying hardware that accepts requests via HTTP or its secure variant HTTPS. A user agent, commonly a web browser or web crawler, initiates communication by making a request for a web page or other resource using HTTP, and the server responds with the content of that resource or an error message. A web server can also accept and store resources sent from the user agent if configured to do so.

A Uniform Resource Name (URN) is a Uniform Resource Identifier (URI) that uses the urn scheme. URNs are globally unique persistent identifiers assigned within defined namespaces so they will be available for a long period of time, even after the resource which they identify ceases to exist or becomes unavailable. URNs cannot be used to directly locate an item and need not be resolvable, as they are simply templates that another parser may use to find an item.

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. Similarly, domain redirection or domain forwarding is when all pages in a URL domain are redirected to a different domain, as when wikipedia.com and wikipedia.net are automatically redirected to wikipedia.org.

A persistent uniform resource locator (PURL) is a uniform resource locator (URL) that is used to redirect to the location of the requested web resource. PURLs redirect HTTP clients using HTTP status codes.

In computer hypertext, a URI fragment is a string of characters that refers to a resource that is subordinate to another, primary resource. The primary resource is identified by a Uniform Resource Identifier (URI), and the fragment identifier points to the subordinate resource.

URL encoding, officially known as percent-encoding, is a method to encode arbitrary data in a Uniform Resource Identifier (URI) using only the limited US-ASCII characters legal within a URI. Although it is known as URL encoding, it is also used more generally within the main Uniform Resource Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform Resource Name (URN). As such, it is also used in the preparation of data of the application/x-www-form-urlencoded media type, as is often used in the submission of HTML form data in HTTP requests.

<span class="mw-page-title-main">URI normalization</span> Process by which URIs are standardized

URI normalization is the process by which URIs are modified and standardized in a consistent manner. The goal of the normalization process is to transform a URI into a normalized URI so it is possible to determine if two syntactically different URIs may be equivalent.

<span class="mw-page-title-main">HTTP referer</span> HTTP header field

In HTTP, "Referer" is an optional HTTP header field that identifies the address of the web page, from which the resource has been requested. By checking the referrer, the server providing the new web page can see where the request originated.

<span class="mw-page-title-main">HTTP 403</span> HTTP status code indicating that access is forbidden to a resource

HTTP 403 is an HTTP status code meaning access to the requested resource is forbidden. The server understood the request, but will not fulfill it, if it was correct.

<span class="mw-page-title-main">HTTP 301</span> HTTP response status code

HTTP 301 is the HTTP response status code for 301 Moved Permanently. It is used for permanent redirecting, meaning that links or records returning this response should be updated. The new URL should be provided in the Location field, included with the response. The 301 redirect is considered a best practice for upgrading users from HTTP to HTTPS.

<span class="mw-page-title-main">WebSocket</span> Computer network protocol

WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011. The current API specification allowing web applications to use this protocol is known as WebSockets. It is a living standard maintained by the WHATWG and a successor to The WebSocket API from the W3C.

A Uniform Resource Locator (URL), colloquially known as an address on the Web, is a reference to a resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifier (URI), although many people use the two terms interchangeably. URLs occur most commonly to reference web pages (HTTP/HTTPS) but are also used for file transfer (FTP), email (mailto), database access (JDBC), and many other applications.

<span class="mw-page-title-main">PATCH (HTTP)</span> Request method in the HTTP protocol

In computing, the PATCH method is a request method in HTTP for making partial changes to an existing resource. The PATCH method provides an entity containing a list of changes to be applied to the resource requested using the HTTP Uniform Resource Identifier (URI). The list of changes are supplied in the form of a PATCH document. If the requested resource does not exist then the server may create the resource depending on the PATCH document media type and permissions. The changes described in the PATCH document must be semantically well defined but can have a different media type than the resource being patched. Languages such as XML or JSON can be used in describing the changes in the PATCH document.

<span class="mw-page-title-main">Well-known URI</span>

A well-known URI is a Uniform Resource Identifier for URL path prefixes that start with /.well-known/. They are implemented in webservers so that requests to the servers for well-known services or information are available at URLs consistent well-known locations across servers.

References

  1. Richardson, Leonard (2007). RESTful Web Services . Sebastopol: O'Reilly. pp.  228–230. ISBN   978-0-596-52926-0.
  2. "Location". Hypertext Transfer Protocol -- HTTP/1.1. IETF. June 1999. sec. 14.30. doi: 10.17487/RFC2616 . RFC 2616.
  3. IETF HTTPbis Working Group Ticket 185
  4. "Location". Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. IETF. June 2014. sec. 7.1.2. doi: 10.17487/RFC7231 . RFC 7231.
  5. Uniform Resource Identifier (URI): Generic Syntax. IETF. January 2005. doi: 10.17487/RFC3986 . RFC 3986.
  6. "IANA Uniform Resource Identifier (URI) Schemes" . Retrieved 2014-11-21.
  7. 1 2 "Relative Reference". Uniform Resource Identifier (URI): Generic Syntax. IETF. January 2005. sec. 4.2. doi: 10.17487/RFC3986 . RFC 3986 . Retrieved 2020-11-22.
  8. 1 2 "Normal Examples". Uniform Resource Identifier (URI): Generic Syntax. IETF. January 2005. sec. 5.4.1. doi: 10.17487/RFC3986 . RFC 3986 . Retrieved 2020-11-22.
  9. Uri, Aviva. Oxford Art Online. Oxford University Press. 2003. doi:10.1093/gao/9781884446054.article.t087366.
  10. "Merge Paths". Uniform Resource Identifier (URI): Generic Syntax. IETF. January 2005. sec. 5.2.3. doi: 10.17487/RFC3986 . RFC 3986 . Retrieved 2020-11-22.