Redirect WWW For Better SEO

Redirect Non WWW Domain to WWW.Domain For Better SEO

Did you know that http://www.domain.com and http://domain.com are actually seen by the search engines as being two entirely different websites. Many website owners don’t realise this and think that ‘Hey, so long as my site loads that’s good – right?” Well of course it’s great that your site loads, but you are missing out on some good page credibility.

Let’s say that you have some people linking to your website with the www. before your domain name (www.domain.com in our example here). Now lets suggest that there is another group of people that are linking to your website as domain.com. Each of these 2 domains is getting some page ranking due to the incoming links, but if the ‘value’ of those links could be combined, a single domain would receive all that page rank love in one lump. So if the www. version had 30 incoming links and the non www version had 15 links, by assigning a preferred domain (canonical) you would see 45 links coming in to the domain of your choice.

So we have cleared up why you would want to do this, now to discover how to make it happen. You could of course spend every spare minute you have searching the internet for links to your website and contacting everyone to ask them to change how your link appears, but that could well become a full time job. There is a much simpler way of doing this and it involves a redirection command. As our web hosting is based primarily on Linux Servers, the method we are going to be using here is based on Apache using a .htaccess file.

What Is A .htaccess File

Fistly, just a quick note about the .htaccess file. It is a very basic file that you can make with any plain text editor like notepad on a PC or TextEdit on a mac. The dot (.) before the file name indicates that it is a hidden file, so if you create the .htaccess file, DO NOT add the dot in the name until it has been uploaded to the web server or it will disappear. All you need to do is save it on your computer as a plain text file and call it htaccess without the preceding dot(.).

Redirecting Your Domain With A .htaccess File

The .htaccess file needs to contain some specific code that delivers instructions to visiting web browsers. The .htaccess file is the first thing to be read when a browser visits your website and so any changes you make here become live immediately. The first couple of lines in the .htaccess file are required to get things working correctly and to add a level of security. These lines are:

Options +FollowSymlinks
RewriteEngine on

After these lines you can begin to add your instruction or rule to get your URL’s rewritten to begin with www. regardless of what URL was requested. Enter the following code into your .htaccess file below the previous code:

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This little bit of magic tells the browser that if a domain does not start with www. then it should be added. The R=301 part is also stating that this is a permanent redirection and so any previously non www. pages should be replaced with this new destination. This should leave you with a .htaccess file that has the following code inside

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirect WWW.domain To non WWW.

Your preference may be to use the non www. version of your domain for all pages and links, and that is just as easily achieved. In this case your .htaccess file begins with the same 2 lines as before, but this time you add the following code:

RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,L]

This code simply uses a rule to start every URL with www. A .htaccess file can contain many different rules depending on what you need to achieve. As well as setting a canonical domain, you may also need to point an old page to a new one, perhaps because the page url was not descriptive enough or has been removed. We will cover single page and folder (directory) redirection in another web hosting guide.

Where To Put The .htaccess File

Once your .htaccess file is ready, you need to upload it to your web hosting space. If you host your web site with Rediweb Hosting, you can login to your account and select your website in manage hosting to launch the web hosting control panel. Selecting the File Manager will open a view that shows all the files contained in your web hosting. Double click on public_html to enter the ‘root’ directory for your website and click on the Upload button  to select the htaccess file on your computer and upload it. Once you can see the htaccess file has been successfully uploaded and is in your directory, right click on it and choose Rename – changing the name to .htaccess from it’s original name.

Note: If there is already a .htaccess file in your web hosting directory, do not upload a new one. You can only have one of these files so you will need to add your new code into the original .htaccess file.

If you have web hosting elsewhere, you may have a similar Web Hosting Control Panel, or you can use an FTP Client like Transmit to upload your files.

To make things even easier for you, we have created a template .htaccess file for you to download. Inside the file are several rules that are preceded by a comment to explain the purpose of the rule. comments in a .htaccess file begin with a # and are ignored by the server. If you wish to use the template .htaccess file we provide, simply remove the rules that you are not using. Leaving both the non ww rule and the force www rule in the file will cause an error.

There are other htaccess rule examples in this file that we will cover on future guides.

Download The Template .htaccess File Here

 

Leave a Comment

Your email address will not be published. Required fields are marked *