RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Using the above when a user attempts to access your website on http://yourdomain.com they will be redirected to http://www.yourdomain.com.