Redirect non www traffic to use the www before the domain name – htaccess solution
Add the following code to your .htaccess file in your website root folder to redirect all non “www” traffic to use the “www”.
So people typing in http://yourdomain.com will be redirected to http://www.yourdomain.com automatically.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]