Try to use the follow code and have a try. In
httpd.conf LoadModule rewrite_module modules/mod_rewrite.so and also Is AllowOverride set to All in your httpd.conf? Like this: AllowOverride All IN .htaccess RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]