Editing URL redirection

Jump to navigation Jump to search

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.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
[[wikipedia:URL redirection]]
 
[[wikipedia:URL redirection]]
  
=== [[HTTP status codes 3xx]] ===
+
=== 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 (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)
 +
* [[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: http://www.example.org/
 +
Content-Type: text/html
 +
Content-Length: 174
 +
 
 +
<html>
 +
<head>
 +
<title>Moved</title>
 +
</head>
 +
<body>
  
 
=Moved=
 
=Moved=
Line 37: Line 83:
  
 
==== nginx rewrite ====
 
==== nginx rewrite ====
[[Nginx]] has an integrated http [[rewrite]] module,<ref name="T6lN6" /> which can be used to perform advanced URL processing and even web-page generation (with the <code>return</code> directive).  A showing example of such advanced use of the rewrite module is [http://mdoc.su/ mdoc.su], which implements a deterministic [[URL shortening]] service entirely with the help of nginx configuration language alone.<ref name="ltnoQ" /><ref name="sjHzb" />
+
[[Nginx]] has an integrated http rewrite module,<ref name="T6lN6" /> which can be used to perform advanced URL processing and even web-page generation (with the <code>return</code> directive).  A showing example of such advanced use of the rewrite module is [http://mdoc.su/ mdoc.su], which implements a deterministic [[URL shortening]] service entirely with the help of nginx configuration language alone.<ref name="ltnoQ" /><ref name="sjHzb" />
  
 
For example, if a request for <code>[https://www.dragonflybsd.org/cgi/web-man?command=HAMMER&section=5 /DragonFlyBSD/HAMMER.5]</code> were to come along, it would first be redirected internally to <code>/d/HAMMER.5</code> with the first rewrite directive below (only affecting the internal state, without any HTTP replies issued to the client just yet), and then with the second rewrite directive, an [[HTTP response]] with a [[HTTP 302|302 Found status code]] would be issued to the client to actually redirect to the external [[Common Gateway Interface|cgi script]] of web-[[man page|man]]:<ref name="y0ZUF" />
 
For example, if a request for <code>[https://www.dragonflybsd.org/cgi/web-man?command=HAMMER&section=5 /DragonFlyBSD/HAMMER.5]</code> were to come along, it would first be redirected internally to <code>/d/HAMMER.5</code> with the first rewrite directive below (only affecting the internal state, without any HTTP replies issued to the client just yet), and then with the second rewrite directive, an [[HTTP response]] with a [[HTTP 302|302 Found status code]] would be issued to the client to actually redirect to the external [[Common Gateway Interface|cgi script]] of web-[[man page|man]]:<ref name="y0ZUF" />
 +
<syntaxhighlight lang="nginx">
 +
location /DragonFly {
 +
  rewrite ^/DragonFly(BSD)?([,/].*)?$ /d$2 last;
 +
}
 +
location /d {
 +
  set $db "http://leaf.dragonflybsd.org/cgi/web-man?command=";
 +
  set $ds "&section=";
 +
  rewrite ^/./([^/]+)\.([1-9])$  $db$1$ds$2 redirect;
 +
}
 +
</syntaxhighlight>
 +
  
location /DragonFly {
 
  [[rewrite]] ^/DragonFly(BSD)?([,/].*)?$ /d$2 last;
 
  }
 
  location /d {
 
  [[set]] $db "http://leaf.dragonflybsd.org/cgi/web-man?command=";
 
  set $ds "&section=";
 
  rewrite ^/./([^/]+)\.([1-9])$  $db$1$ds$2 redirect;
 
  }
 
  
 
== AWS ==
 
== AWS ==
Line 57: Line 106:
 
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-s3.html#scenario-s3-bucket-website
 
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-s3.html#scenario-s3-bucket-website
 
* https://aws.amazon.com/premiumsupport/knowledge-center/redirect-domain-route-53/
 
* https://aws.amazon.com/premiumsupport/knowledge-center/redirect-domain-route-53/
* [[AWS S3: configuring a webpage redirect]]
 
  
 
== Related terms ==
 
== Related terms ==
Line 63: Line 111:
 
* [[Nginx]]: <code>[[Return (nginx.conf)|return]]</code> and <code>[[rewrite]]</code>
 
* [[Nginx]]: <code>[[Return (nginx.conf)|return]]</code> and <code>[[rewrite]]</code>
 
* [[301]] [[HTTP response status code]].  Redirects (300–399)
 
* [[301]] [[HTTP response status code]].  Redirects (300–399)
* Nginx [[return]] using [[subdomain redirection]]s
+
* Nginx [[return]] using [[subdomain]]s
* [[Lambda@Edge]]
 
* <code>[[curl -L]]</code>
 
* [[Signed URL]]
 
 
 
== Activities ==
 
* [[AWS S3: configuring a webpage redirect]]
 
  
 
== See also ==
 
== See also ==
* {{URL redirection}}
+
* {{nginx}}
 
+
* {{web}}
  
 
[[Category:Web]]
 
[[Category:Web]]

Please note that all contributions to wikieduonline may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wikieduonline:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Advertising: