1

I have this on my .htaccess file and I want add a rule to redirect my site from non-www to www.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115

2 Answers2

0

you can try this

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)index.php$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
-1

I used the code below to redirect my non-www URL to a www one. I added it on my .htaccess file and it works just fine. I hope this code can help you. Just replace the domain name with your own domain name. Good luck.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomainname.com [NC] 
RewriteRule ^(.*)$ http://www.yourdomainname.com/$1 [L,R=301] 
RewriteCond %{THE_REQUEST} ^(.*)index.php
RewriteRule ^(.*)index.php$ http://www.yourdomainname.com/$1 [R=301,L]
Kiel Labuca
  • 1,223
  • 9
  • 13