Place the following configuration in your .htaccess file:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTP_HOST} !=localhost RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This line is placed to make sure that redirection does not occur on your localhost during the development process. You can remove this line if you want to place the .htaccess configuration directly on your production server. Otherwise you can leave it and change “localhost” to any other local web server you are running.
RewriteCond %{HTTP_HOST} != localhost
# permanent redirect (301) Redirect 301 /path new_Url
Redirect 302 /path new_Url