Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
URL redirection
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Implementation == Several different kinds of response to the browser will result in a redirection. These vary in whether they affect [[HTTP headers]] or HTML content. The techniques used typically depend on the role of the person implementing it and their access to different parts of the system. For example, a web author with no control over the headers might use a [[meta refresh|Refresh meta tag]] whereas a web server administrator redirecting all pages on a site is more likely to use server configuration. === Manual redirect === The simplest technique is to ask the visitor to follow a link to the new page, usually using an HTML anchor like: <syntaxhighlight lang="html"> Please follow <a href="https://www.example.com/">this link</a>. </syntaxhighlight> This method is often used as a fall-back β if the browser does not support the automatic redirect, the visitor can still reach the target document by following the link. === HTTP status codes 3xx === In the [[HTTP]] [[Protocol (computing)|protocol]] used by the [[World Wide Web]], a '''redirect''' is a response with a [[List of HTTP status codes|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 ([https://tools.ietf.org/html/rfc7231 RFC 7231]): * [[HTTP 300|300 multiple choices]] (e.g. offer different languages) * [[HTTP 301|301 moved permanently]] (redirects permanently from one URL to another passing link equity to the redirected page) * [[HTTP 302|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) * [[HTTP 303|303 see other]] (forces a GET request to the new URL even if original request was POST) * [[305 Use Proxy|305 use proxy]] (indicates that the client's requested resource is only available through a proxy) * [[HTTP 307|307 temporary redirect]] (provides a new URL for the browser to resubmit a GET or POST request) * [[HTTP 308|308 permanent redirect]] (provides a new URL for the browser to resubmit a GET or POST request) Status codes [[HTTP 304|304 not modified]] and [[HTTP 305|305 use proxy]] are not redirects. {| class="wikitable" |+ {{Anchor|Redirect_status_codes_and_characteristics}} Redirect status codes and characteristics<ref name="G1Lfc" /> |- ! 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 || {{no2|not by default}} || GET / POST may change |- | 303 || HTTP/1.1 || Temporary || {{no|never}} || always GET |- | 307 || HTTP/1.1 || Temporary || {{no2|not by default}} || may not change |- | 308 || HTTP/1.1 || Permanent || {{yes2|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: <syntaxhighlight lang="http"> HTTP/1.1 301 Moved Permanently Location: https://www.example.org/ Content-Type: text/html Content-Length: 174 <html> <head> <title>Moved</title> </head> <body>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)