Force The WWW Prefix On Your Website
One of the very first things you should do when developing your website is decide if you want the WWW prefix on your domain or not.
It’s very important to do this for SEO purposes, because if your site can be access with and without the WWW prefix, it can result in duplicate content in the search engine listings, which you can be penalized for.
Another good reason to do this, especially with ecommerce stores, is for the sake of the SSL certificate. Apparently, some hosting companies, like GoDaddy, will recommend you buy two SSL certificates, one for the WWW domain and one for without.
That makes no sense though. Save your money and add one of the following lines to your .htaccess file, right after the RewriteEngine On part:
Note: If you don’t know where the .htaccess file is, it’s located in the first level directory of Magento, where you’ll also find the index.php, install.php, pear, and favicon.ico files.
Add WWW Prefix |
The following will force the WWW prefix on your domain. This is the preferred method.
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Remove WWW Prefix |
This is the exact opposite of the previous example, it will strip the WWW prefix from your domain. I personally feel that it looks “naked” without the WWW prefix, but it’s your choice.
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
Additional Resources |
Want some more examples on how you can use mod_rewrite to enhance your site? Check out our blog article.


