RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301]
Please note that the .htaccess should be located in the web site main folder.
The dot in front makes it ivisible so use your ftp client setting to dsplay hidden files..
This will redirect all requests from the non-www version of your site to the www version using 301 Permanent redirect which will make the search engines to index your site only using the www.your_domain.com URL. In this way you will avoid a duplicate content penalty.
When you have also aliases running on your site and you want top keep these intakt, than this system isn't working for you: it is forwarding to a domain.com.
A much nicer way is than this one, which you can just copy/past on all your websites:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
