Add/Remove www using mod_rewrite and .htaccess
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.
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
If you wanted to remove the www you can use the following:
Any problems, drop a line below or add your favourite
.htaccess tips and tricks.