How to Redirect a Website to Remove the ‘www’
Friday, May 30th, 2008Several months ago, I read in a blog where Matt Cutts spoke at a Wordpress Bootcamp. He specifically said that with Google, a website with www and the same website without the www are treated as two separate websites. What I take from this is that if you trying to maximize your search engine results, it is better if you either stick with one or the other for your incoming links.
So the question comes up when using Apache as your webserver, how can you take your new website and redirect the www to the base url name. In my example, I wanted http://www.wilderness-gear.com to redirect to http://wilderness-gear.com. The answer is simple, use the .htaccess file.
Go to your base directory and check if you have a hidden file called .htaccess. If you have one, then back it up immediately. Your web application may be using it. Wordpress does. My example here is for a website that did not have an .htaccess file in the base directory. So all I did was create the .htaccess file in the base directory and add the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.wilderness-gear\.com$ [NC]
RewriteRule ^(.*)$ http://wilderness-gear.com%{REQUEST_URI} [R=301,L]
</IfModule>
All done. Now the http://www.wilderness-gear.com redirects to http://wilderness-gear.com.