Redirect: HTTP status codes 3xx

From wikieduonline
Revision as of 13:35, 27 August 2021 by Welcome (talk | contribs) (→‎See also)
Jump to navigation Jump to search

In the HTTP protocol used by the World Wide Web, a redirect is a response with a status code beginning with 3 that causes a browser to display a different page. If a client encounters a redirect, it needs to make a number of decisions how to handle the redirect. Different status codes are used by clients to understand the purpose of the redirect, how to handle caching and which request method to use for the subsequent request.

HTTP/1.1 defines several status codes for redirection (RFC 7231):

  • 300 multiple choices (e.g. offer different languages)
  • 301 moved permanently (redirects permanently from one URL to another passing link equity to the redirected page)
  • 302 found (originally "temporary redirect" in HTTP/1.0 and popularly used for CGI scripts; superseded by 303 and 307 in HTTP/1.1 but preserved for backward compatibility)
  • 303 see other (forces a GET request to the new URL even if original request was POST)
  • 307 temporary redirect (provides a new URL for the browser to resubmit a GET or POST request)
  • 308 permanent redirect (provides a new URL for the browser to resubmit a GET or POST request)

Status codes 304 not modified and 305 use proxy are not redirects.

Script error: No such module "anchor". Redirect status codes and characteristics[1]
HTTP Status Code HTTP Version Temporary / Permanent Cacheable Request Method Subsequent Request
301 HTTP/1.0 Permanent Yes GET / POST may change
302 HTTP/1.0 Temporary not by default GET / POST may change
303 HTTP/1.1 Temporary never always GET
307 HTTP/1.1 Temporary not by default may not change
308 HTTP/1.1 Permanent by default may not change

All of these status codes require the URL of the redirect target to be given in the Location: header of the HTTP response. The 300 multiple choices will usually list all choices in the body of the message and show the default choice in the Location: header.

Example HTTP response for a 301 redirect

A HTTP response with the 301 "moved permanently" redirect looks like this:


HTTP/1.1 301 Moved Permanently
Location: http://www.example.org/
Content-Type: text/html
Content-Length: 174

<html>
<head>
<title>Moved</title>
</head>
<body>

Related terms

See also

  • Cite error: Invalid <ref> tag; no text was provided for refs named G1Lfc
  • Advertising: