Everyone who works with web design and websites know that however good you plan things you will sooner or later need to move a page while still wanting the visitor to find the page they are looking for. The best way to do this is to redirect your visitors so that they automatically arrive at the right page. This can be done for individual pages or for an entire domain if you or your client for whatever reason has decided to change web address.
There are several ways to redirect your visitors and some are better than others, especially if you consider the effects these redirects have on SEO efforts. Some can let you move almost all link power etc to your new domain while others can on some occasions actually hurt both your new and your old domain. If a page has moved permanently you should make sure to use a 301 redirect as that tells the search engines and bots that the page has moved permanently. Using other redirects will not have even close to the same beneficial effect.
Let’s start by looking at a redirect that don’t have a lot of effect on user experience but that can help a lot with SEO: redirecting none-WWW to WWW or vise versa. If you do not do this your site will exist on two different URL:s in the eyes of Google. Google is usually but not always smart enough to realize that it is the same site, so it is good to do the redirect just in case to make sure. We are going to do this server-side through a htaccess 301 redirect. Htaccess is a feature available on servers having the Apache Mod-Rewrite module enabled.
To redirect the none-WWW to WWW add the following to the .htaccess file
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.domain.com with your actual domain name.
The .htaccess file should be placed in your web root folder. If you do not have a .htaccess file already you can create one by adding the text above to a blank document in notepad, save it as .htaccess and upload it to your root folder.
Now let’s assume that you have changed your domain and want to redirect every page of your site to the corresponding URL on the new domain. That too is easy to do in the htaccess file and the code is as you will see very similar to the one we just used.
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Please REPLACE www.newdomain.com in the above code with your actual domain name.
Some sources recommend that you also contact people linking to your site and ask them to update their links. We recommend against this as an aged link carries more power than a new one. You can use the same technique to redirect a singel page that you moved to a new location.
I recommend that you always 301 redirect any url if you remove that page to make sure that you never lose any link power. If you moved the page then you should redirect the old url to the new location. If you removed the page completely then it is usually best to redirect the URL to index or to the main page in the relevant section. Doing this can dramatically improve your rankings. We did this for this website and they saw a 30% increase in traffic from the search engine as a result. Other sites where we have 301 redirected broken URL:s have seen a 20-55% improvement.
If you do not feel comfortable messing with the htaccess file (errors can cause the site to become unavailable until you fix them) there are plenty of other ways to accomplish a redirect. One method that is not language specific is to use an internet Service Manager or IIS redirect. You will find the internet service manager in your control panel. Enter the internet service manager, choose the file or folder you want to redirect and then select “a redirection to a URL”. Enter the new URL, check the “The exact url entered above” and the “A permanent redirection for this resource” and then press Apply. Test the new redirect. If it doesn’t work, remove it and try creating a new one.
Examples of other language specific codes to redirect visitors
PHP Redirect
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>
JSP (Java) Redirect
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>
ASP Redirect
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>
ASP .NET Redirect
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>
ColdFusion Redirect
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">
Ruby on Rails Redirect
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end
CGI PERL Redirect
$q = new CGI;
print $q->redirect("http://www.new-url.com/");