We aim to respond to all messages within 1 business day. You'll be hearing from us soon!
In the meantime, perhaps you'd like to learn more...
In our previous post SEO Considerations When Redesigning a Website we touched on how to mitigate the ill effects of changing your website domain or file names by using 301 Permanent Redirects. Here we will give you instruction on how to set up this redirect on both Apache and Microsoft IIS web servers.
The “301 Permanent Redirect” is the most efficient and search engine friendly method for redirecting websites. Situations include:
Here is Google’s webmaster guideline on 301 redirects: http://www.google.com/support/webmasters/bin/answer.py?answer=93633
The Linux Operating system most commonly uses Apache web server. There are a number of methods of redirect available:
.htaccess Method
If you have sufficient access to the web server then the very best method of redirection is the creation and upload of an .htaccess file as this gives you the most flexibility and control:
Apache .htaccess Single Page Redirect
You will need to create a file named .htaccess (no extension), add the code below to the file using a text only editor and upload it to the root directory of your website:
RewriteEngine on
Redirect 301 /oldpage.html http://www.example.com/newpage.htmlApache .htaccess Canonical Redirect
Again you will need to create a file named .htaccess, add the code below to
the file using a text only editor and upload it to the root directory of your website. The code below will redirect all visitors accessing http://domain.com to http://www.domain.com:RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Control Panel Method
If you have Administrator access to the cPanel then this is another method of redirection but you may find that you are limited with the types of redirects that you can do, for example the Plesk control panel does not allow for 301 redirects.
cPanel redirect
Log into your cPanel, and look for "Redirects" under Site Management
Put in the current directory into the first box
Put the new directory in the second box
Choose the type (temporary or permanent) temporary=302 and permanent=301
Click "Add" and you're done
On Page Redirects
In instances where you are only wishing to redirect one or two files and perhaps don’t have the server correctly configured for an .htaccess file or where you do not have sufficient access to the web server such as in a shared hosting environment, you can use on-page redirects.
Read more info on both PHP and ASP redirects.
IIS supports the requirement for 301 redirection and all necessary changes can be made directly through the Control Panel.
Administrator Mode
If you can log into the Windows 2000 (or higher) server and access the desktop, then this is the best method to carry out redirects in a Windows environment. The example below is based on the IIS 6.0 platform.
On Page Redirects – See Below
PHP Single Page Redirect
In order to redirect a static page to a new address simply enter the code below inside the index.php file. This code must be located in a script that is executed on the server before the page content starts:
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>
PHP Canonical Redirect
The code below will redirect all visitors accessing http://domain.com to http://www.domain.com. This code must be located in a script that is executed in every page on the server before the page content starts:
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>
ASP Single Page Redirect
This redirect method is used with the Active Server Pages platform. This code must be located in a script that is executed on the server before the page content starts:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader='Location','http://www.new-url.com/'
%>
ASP Canonical Redirect
The code below will redirect all visitors accessing http://domain.com to http://www.domain.com. This code must be located in a script that is executed in every page on the server before the page content starts:
<%
If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","<a href="http://www/">http://www</a>."
& Request.ServerVariables("HTTP_HOST")
& Request.ServerVariables("SCRIPT_NAME")
End if
%>
These are some of the methods available to ensure you preserve your Internet footprint when updating your site content.
Disclaimer
All care has been taken in preparing the code in this blog, however no guarantee is offered as to the suitability of this code for your particular hosting environment. We suggest you copy the code into a text editor to remove all formatting. No responsibility is accepted for errors or omissions.
Written by Karyn Ogier
Here from the very beginning, Karyn was originally a co-founder of Apex Digital and carried the Strategy & Marketing Director title for more than two decades. Karyn switched gears at the end of 2018 when she returned to study in a new field. Now in a contract Content Writer capacity, she has a wealth of knowledge in the industry and has been...We aim to respond to all messages within 1 business day. You'll be hearing from us soon!
In the meantime, perhaps you'd like to learn more...