Redirect non www to www in htaccess

I want to redirect my dmoain always with www i am using this code but not working. <IfModule mod_rewrite.c><p /> <xmp>RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
Harsh Aggrawal
Asked 13-11-2019
69

Answer (1)
Hi,  replace your .htaccess with this, this will works for you Tested. <IfModule mod_rewrite.c><p /> <xmp>RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] </IfModule>
Deepak Sharma
Asked 02-10-2018
45 Likes
Comments
Write comment

Submit your answer