Force The WWW Prefix On Your Website

Last modified by Crucial on Mon, May 26, 2008 18:33
Source|Old Revisions  |  Back To Group

This is an old revision of the document!

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:

Add WWW Prefix

The following will force the WWW prefix on your domain. This is the preferred method.

RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$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} ^$ [NC]
RewriteRule ^(.*)$$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.


Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs