TutorialsRoom.com
RSS Feed

Subscribe: RSS or e-mail

Home » Web Development » SEO »

WWW vs. Non-WWW, The PageRank, The Effect And The Solution

WWW vs. Non-WWW, The PageRank, The Effect And The Solution
Have you ever wondered if there is a difference between using http://www.anysite.com and http://anysite.com for your site links? Does this affect your PageRank? Read on.


So can you use both www.yoursite.com and yoursite.com to link to your site? Yes you can, but I strongly recommend that you don't!
Why? For SEO (Search Engines Optimization) reasons you should always use the same form for your links, pick one (with www or without www) and stick to it. This is called canonicalization and it means picking the best URL when you have a choice.

Here is the explanation:

Because www.yoursite.com is not the same as yoursite.com and if you have different inbound links to both URLs, this could cause two problems:

First, some search engines might "think" that this is a duplicate content and penalize your site for this!

Second, splitting your links will affect your PageRank as PageRank is all about links, so if you have 1000 inbound links to www.yoursite.com and 500 inbound links to yoursite.com then you will have different PageRank for both URLs and you will lose valuable inbound links because they will be split into links for both URLs.

So what is the solution for this problem?

First, choose one form and stick to it. I prefer www.yoursite.com because this is what most people use. Also most people press (CTRL + Enter) in Internet Explorer or Firefox to append http://www and .com to whatever they have typed in the address bar of both major browsers.

Second, in Google's Webmaster Tools, click "Preferred domain" and choose the same URL that you chose in the previous step.

Third, do something to redirect your traffic from one URL to the other (like from non-www to the www). That is what the major sites have done, try typing google.com, msn.com or yahoo.com and you will be redirected to www.google.com, www.msn.com and www.yahoo.com. The right method is to use "301 Moved Permanently" as this will make sure that search engines will combine the value of your inbound links.

I will show you two methods to do that. The best and the most frequently used method to do that is in a file called .htaccess (HTTP Access). It's a text file used in most Linux based web servers. Just make a text file called .htaccess and upload it to the root directory of your site or append those lines to it if the file is already there:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
This will redirect all the traffic from the non-www to the www of your site with the "301 Moved Permanently" server response.

As I have told you this is the best and the fastest method, but what if you - for some reason - can not use the .htaccess method?

You can use PHP, just add those lines to your home page, but make sure they are the first lines in the page or you will get an error "headers already sent".
<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www')
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.yoursite.com/');
}
?>
While you need to put one .htaccess file in the root directory of your site and all the pages in your site will work properly, this is not the case for the PHP method, that's why I have told you that the .htaccess method is better. The previous PHP code will work only for the home page so you need to add those lines to the top of every page you want to redirect from the non-www to the www URL:
<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www')
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
}
?>
You can put those lines in an external PHP file and use PHP Include function to include this file.

Remember:

Always use the .htaccess file method if you can.
Do not forget to replace "yoursite.com" with your domain name.
Rating: 3.2/5 (49 Votes)
10 Comments
TutorialsRoom said,
May 20th, 2013

Thank you! If you see how much spam comments I get, you may know why they disable comments.

May 20th, 2013

I’ve been missing this. This is just the information that I needed. Great post, very interesting, thank-you for sharing! I will check back soon for more interesting article posts! I hardly ever comment on blogs that do have comments. The main reason is, you spend the time to read an article, then comments only to find that they do not accept comments anymore. You have touched some good factors here.

May 8th, 2013

i have my blog at www.trickonics.com how can i redirect trickonics.com to www.trickonics.com ?? Blog is hosted on Blogger.com and there doesn't have any PHP option available ...

February 26th, 2013

Thank you for this tip! I prefer to use the "www.brunocunha.com" address instead of "brunocunha.com" and this article was an excellent help to implement this redirection. Thank you again!

Stuart said,
December 9th, 2012

Thanks for the post, I do prefer the .htaccess way. But what I like the most is Wordpress! It handles all the redirects for you, very simple indeed!

Geek said,
September 21st, 2012

What IF: the website has an index.html as a home page and .html extension has been set on the server as the first priority. So if you will use the index.php redirection, it will not work because it will pull up the index.html file first. If you will rename the index.html file to myhome.html file and set header('Location: http://www.yoursite.com/myhome.html'; this doesn't do it because it is no longer redirecting to the base url with 'www' version Any idea about this? or a workaround?

August 16th, 2012

Thank you very much...

July 3rd, 2012

I saw a site no-www.com, or something like that, the community there is struggling for no-www domains at all. It os rather interesting to read, what they are saying.

Zyxel said,
April 27th, 2012

Thank you, I think everyone knows how to do redirect. Anyway www and -www - it soesn't matter - just stay away from thin and duplicate content.

January 23rd, 2012

If your trying to resolve the redirect from either non www or the www then go into the .htaccess file if you cant find it make sure your web hosting company allows you to view hidden files. If your using cpanel this can be easily done click file manager and select the root DIR allowing hidden files to be viewed. Find the .htaccess and simpilly add this string: RewriteEngine On RewriteCond %{HTTP_HOST} ^YOURSITE.co.uk [NC] RewriteRule ^(.*)$ http://www.YOURSITE.co.uk/$1 [L,R=301] This will perform a successful redirect. Many tutorials regarding the www vs non www cause confusion this was interesting!

Post Your Comment (In English):



(Optional, will not be shown)


(Optional)




Please notice that comments which are not related and those with live links will be deleted.

Copyright © 2007-2013 Hazem Osman. All rights reserved. Terms & Conditions