Making sure that your website's domain name is being accessed from only one domain is important, though at first glance it may not be obvious exactly why. Google's PageRank system checks the back-links to your site on the web to try to get an idea of how important your site is overall. However, in this process it may consider example.com to be a different site from www.example.com. To prevent this from happening, you'll need to redirect your users from the non www domain, to the www one.
Simply create, a .htaccess file and add the following script to it. Just make sure to replace the example.com with your own domain name.
# To redirect all users to access the site WITH the www. prefix
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]