Use .htaccess to redirect non-www to www

This is the code to use in an apache server environment to redirect non-www requests to the www subdomain for your website.

Options -Indexes +FollowSymlinks
RewriteEngine on
RewriteBase /
### Non-www Requests to www Requests ###
RewriteCond %{HTTP_HOST} ^YourDomain\.com [NC]
RewriteRule ^(.*)$ http://www.YourDomain.com/$1 [L,R=301]

Use this to ensure that visitors view your website as [www.YourDomain.com]