Redirects with Server Side Scripting
If you have a dynamically driven (server side) web site, you can implement one or more of the following scripts, depending on which scripting language(s) you use.
These portions of code are fairly self-explanatory. They simply provide the appropriate 301 response header, and the location of the new page.
HTTP 301 Redirect in ASP-VBScript
Include the following ASP code at the top of each page:
<%@ Language=VBScript %>
' Permanent redirection
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.dexterityunlimited.com/"
HTTP 301 Redirect in ColdFusion
Include the following ColdFusion code at the top of each page:
<CFHEADER statuscode="301" statustext="Moved Permanently">
<CFHEADER name="Location" value="http://www.dexterityunlimited.com/">
HTTP 301 Redirect in PHP
Include the following PHP code at the top of each page:
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
HTTP 301 Redirect in Perl
Include the following Perl code at the top of each page:
print "Status: 301 Moved Permanently\n";
print "Location: http://somewhere/page.htm\n\n";
HTTP 301 Redirect in JSP/Java
Include the following Java code at the top of each page:
response.setHeader( "Location", "http://www.dexterityunlimited.com/" );
response.setHeader( "Connection", "close" );
Redirecting with .htaccess
If you are on an Linux/Apache server, or a Microsoft Windows Server that can run Apache modules, you can do your redirects with an .htaccess file.
The .htaccess file is a very powerful tool, but can wreak havoc on a site if not implemented correctly. Always save a backup of any existing .htaccess file before attempting any changes.
Redirection with mod_rewrite
The following lines redirect the client to a new location. In this case, a request for the file contact.php is sent to the file contact-us.php:
rewriteRule ^contact\.php$ http://www.dexterityunlimited.com/contact-us.php [R=permanent,L]