Force www on all your domains

Thu. 12. January 2012 Snippets Manuel
Force www on all your domains

A generic piece of code you can drop in all of your .htaccess files to force "www." no matter what the domain name is.

I like to have all my websites set up with "www." to avoid SEO and cookie issues (when using the FEU module to allow user logins).

The code below will work on any domain name so it's really easy to include it in your "default" .htaccess.

<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

ps: don't forget to disable this when working on your localhost or testing cmsms setups trough the server IP!

UPDATE:
Below you will find the generic code to remove the www on any domain:

<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>

Greetings,
Manuel



Article was created by Manuel

Manuel

I'm a cmsms addict from Belgium. I had to check my forum profile but it has apparently started in 2007 :)

« Back to Articles

Comments

Categories

Archive

From Twitter

I love CMSMS

Designed and developed by idea arts. I do this! © Copyright 2010-2013

Go back to Top