How to enforce users to use www. with .htaccess?

Date added: 09 February 2012 Last revised: 09 February 2012 Hits:

You may wish to apply this code into your .htaccess IF you are experiencing errors with the leech system where the site is added as http://www.mysite.com" target="_blank and a user enters from mysite.com ( no www. ) or vice verse.

to direct a user to your site WITH the www. - add this to your .htaccess changing mysite.com to your own domain.

    RewriteCond %{HTTP_HOST} ^mysite.com [NC]
    RewriteRule ^(.*)$ http://www.mysite.com/