How to Redirect and Forcing WWW in URL with .htaccess file
Redirecting a URL
Using Redirect in an .htaccess file enables you to redirect users from an old page to a new page without having to keep the old page. For example, if you use index.html as your index file and then later rename index.html to home.html, you could set up a redirect to send users from index.html to home.html. For example:
Redirect /path/to/old/file/old.html http://www.example.com/new/file/new.html
The first path to the old file must be a local UNIX path, NOT the full path. So, if the .htaccess file is in the directory /example.com, you would not include /home/exampleuser/example.com in the local UNIX path. The first / represents the example.com directory. If the old file was in that directory, you would follow the / with the old file name.
The second path to the new file can be a local UNIX path, but can also be a full URL to link to a page on a different server or the same server.
Forcing www in the URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]