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
Hi Tetsuo,
The SEO issue only exists if you don't force a policy concerning the usage of www on your domain. If you make a choice to always remove or always add the www you are safe :) (I've updated the article with the generic code to remove the www - Ctrl F5 might be required to refresh your browser's cache)
If you allow users to log in with the FEU module, each user can remember his/her login by checking the "remember me" checkbox. The cookie created to remember the login is related to either the www or the non-www version of your domain, it won't work on both.
Greetings, Manuel
My preference has always been to exclude the www. for a site, as it should never be necessary, plus it just looks better in my opinion.
I wasn't aware of there being any SEO benefit to having a www., care to elaborate on this and the FEU issue? :)
Thx for the feedback, glad to see you find it useful! :)
Greetings, Manuel
works great!