In this tutorial we show you how to redirect any traffic going to your domain without the www. ,even if it is typed in without it, this code will automatically add it for you.

The following code needs to be added to your exisiting .htaccess file. If you dont currently have this file then do the following
  1. Create an empty text file using a text editor such as notepad, and save it as htaccess.txt.[/*]
  2. If using a text editor, be sure to save the file as plain text.[/*]
Once you have created the file rename it to .htaccess, note the .txt has been removed. The file must have this name to work correctly.

Add the following code to the file and upload to your server.
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]

RewriteCond %{HTTP_HOST} ^www.domain.com$

RewriteRule ^/?$ "http://www.domain.com" [R=301,L]
Now, all your traffic will be redirected to the full domain and prefixed with www.