Reputation: 1223
I want to redirect my non www domain to www and to a subfolder
I was able to redirect the domain to the subfolder with this code
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]
now I want to redirect my domain to www. how do I do that?
if I try to add www infront of my doman it still shows a non-www domain
Upvotes: 1
Views: 99
Reputation: 41219
You can use this :
RewriteEngine on
#redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^.*$ http://%1%{REQUEST_URI} [NE,L,R]
# rewrite /root to subfolder
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]
Upvotes: 1