Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Force The WWW Prefix On Your Website

Last modified by Crucial on Thu, September 18, 2008 00:56
Source|Old Revisions  |  Back To Group

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.




 

Popular Wiki Tags  |  View all

 routes   module   list   data accessing   resource   action   backend   mysql4   api   controller   php   getModel   attribute   eav   reference 

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
50108 users|473 users currently online|102247 forum posts