Remove www from URL w/ mod_rewrite

In order to make sure that all SEO juice is combined to the same variation of your URL, it is important to either force remove the www from your URL, or force add the www to your URL. This is the code to remove the www from your URL:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

It utilizes the mod_rewrite module for apache, so make sure that you have mod_rewrite enabled. Add the code to your .htaccess file(or directly in your apache config), and change the domain to match yours and you should be all set.

Posted by Will on May 21, 2012

Leave a Reply

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