Beware this content is over 7 years old and considered stale. It may no longer be accurate and/or reflect the understanding of the author but remains here for reference only. Please keep this in mind as you use this content.

URL uniformity is important for Search Engine Optimisation (SEO) reasons because to a search engine, http://www.example.org, is not necessarily the same website as http://example.org and often they can be treated differently and attain different rankings.

Where this becomes a problem is if you are engaged in SEO practices to improve your overall Search Engine Ranking you need to focus your efforts on promoting your URL in a single uniform way to avoid the possibility of PageRank splitting.

Effectively, Google sees your website as two web sites and any backlinks or inbound links to your site point to either the version of your domain name with the www and to the version of your domain name without the www. Therefore, the PageRank is also unique for both variations of your domain name and this can result in a lower than normal PageRank.

One way around this, is to force the automatic rewrite of URLs to your preferred variation of your URL using Apache’s mod_rewrite and the .htaccess file in the root of your website directory.

What I’ve come to discover is that there are a lot of variations of this information online but the method I prefer is as follows (remember to change example.com for your domain name):

1
2
3
4
5
6
Options FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]

How this version differs is it allows the rewriting of an entire URL to the preferred version, in this case above, to the version to include the www.

So if someone entered http://example.com/contact/ in to their address bar, it would be re-written successfully to http://www.example.com/contact/

If you wanted to remove the www you can use the following:

1
2
3
4
5
6
Options FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,NC]

Any problems, drop a line below or add your favourite .htaccess tips and tricks.