URL redirection 324
<title>Moved</title>
</head>
<body>
<h1>Moved</h1>
<p>This page has moved to <a href="http://www.example.org/">http://www.example.org/</a>.</p>
</body>
</html>
Using server-side scripting for redirection
Often, web authors don't have sufficient permissions to produce these status codes: The HTTP header is generated by
the web server program and not read from the file for that URL. Even for CGI scripts, the web server usually
generates the status code automatically and allows custom headers to be added by the script. To produce HTTP
status codes with cgi-scripts, one needs to enable non-parsed-headers.
Sometimes, it is sufficient to print the "Location: 'url'" header line from a normal CGI script. Many web servers
choose one of the 3xx status codes for such replies.
Frameworks for server-side content generation typically require that HTTP headers be generated before response
data. As a result, the web programmer who is using such a scripting language to redirect the user's browser to
another page must ensure that the redirect is the first or only part of the response. In the ASP scripting language, this
can also be accomplished using the methods response.buffer=true and response.redirect
"http://www.example.com/". Using PHP, one can use the header function as follows:
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.example.com/');;)
exit();
According to the HTTP protocol, the Location header must contain an absolute URI.[5] When redirecting from one
page to another within the same site, it is a common mistake to use a relative URI. As a result most browsers tolerate
relative URIs in the Location header, but some browsers display a warning to the end user.
There are other methods that can be used for performing redirects, but they do not offer the flexibility that
mod_rewrite offers. These alternative rules use functions within mod_alias:
Redirect permanent /oldpage.html http://www.example.com/newpage.html
Redirect 301 /oldpage.html http://www.example.com/newpage.html
To redirect a requests for any non-canonical domain name using .htaccess or within a <Directory> section in an
Apache config file: