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]] ===
 
  
=Moved=
 
<p>This page has moved to <a href="http://www.example.org/">http://www.example.org/</a>.</p>
 
</body>
 
</html>
 
</syntaxhighlight>
 
 
==== Using server-side scripting for redirection ====
 
Web authors producing HTML content can't usually create redirects using HTTP headers as these are generated automatically by the web server program when serving an HTML file.  The same is usually true even for programmers writing CGI scripts, though some servers allow scripts to add custom headers (e.g. by enabling "non-parsed-headers").  Many web servers will generate a 3xx status code if a script outputs a "Location:" header line.  For example, in [[PHP]], one can use the "header" function:
 
 
<syntaxhighlight lang="php">
 
header('HTTP/1.1 301 Moved Permanently');
 
header('Location: http://www.example.com/');
 
exit();
 
</syntaxhighlight>
 
 
More headers may be required to prevent caching.<ref name="php-301-robust-solution" /> The programmer must ensure that the headers are output before the body.  This may not fit easily with the natural flow of control through the code.  To help with this, some frameworks for server-side content generation can buffer the body data.  In the [[Active Server Pages|ASP scripting]] language, this can also be accomplished using <code>response.buffer=true</code> and <code>response.redirect <nowiki>"http://www.example.com/"</nowiki></code> HTTP/1.1 allows for either a relative URI reference or an absolute URI reference.<ref name="venDA" /> If the URI reference is relative the client computes the required absolute URI reference according to the rules defined in RFC 3986.<ref name="3Y1IG" />
 
 
==== Apache HTTP Server mod_rewrite{{anchor|mod_rewrite}} ====
 
The [[Apache HTTP Server]] mod_alias extension can be used to redirect certain requests. Typical configuration directives look like:
 
<syntaxhighlight lang="apache">
 
Redirect permanent /oldpage.html http://www.example.com/newpage.html
 
Redirect 301 /oldpage.html http://www.example.com/newpage.html
 
</syntaxhighlight>
 
 
For more flexible [[URL rewriting]] and redirection, Apache mod_rewrite can be used. E.g., to redirect a requests to a canonical domain name:
 
<syntaxhighlight lang="apache">
 
RewriteEngine on
 
RewriteCond %{HTTP_HOST} ^([^.:]+\.)*oldsite\.example\.com\.?(:[0-9]*)?$ [NC]
 
RewriteRule ^(.*)$ http://newsite.example.net/$1 [R=301,L]
 
</syntaxhighlight>
 
 
Such configuration can be applied to one or all sites on the server through the server configuration files or to a single content directory through a <code>[[.htaccess]]</code> file.
 
 
==== 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" />
 
 
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" />
 
 
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 ==
 
* https://aws.amazon.com/premiumsupport/knowledge-center/elb-redirect-to-another-domain-with-alb/
 
** https://aws.amazon.com/blogs/aws/new-host-based-routing-support-for-aws-application-load-balancers/
 
* https://aws.amazon.com/premiumsupport/knowledge-center/route-53-redirect-to-another-domain/
 
** Using [[ALB]]: <code>[[AWS::ElasticLoadBalancingV2::Listener]]</code>, action: redirect
 
* 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 ==
* [[S3 bucket]]: <code>[[AWS::S3::Bucket]]</code>, <code>[[AWS::S3::Bucket WebsiteConfiguration]]</code>
+
* [[S3 bucket]]: <code>[[AWS::S3::Bucket]]</code>
* [[Nginx]]: <code>[[Return (nginx.conf)|return]]</code> and <code>[[rewrite]]</code>
 
* [[301]] [[HTTP response status code]].  Redirects (300–399)
 
* Nginx [[return]] using [[subdomain redirection]]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: