Reputation: 10771
As a way of changing my document root, I'm trying to perform a redirect in htaccess.
This redirects to /subfolder without it showing in the url but doesnt remove www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !subfolder/
RewriteRule (.*) /subfolder/$1 [L]
How would I go about redircting www
and non-www
to non-www.domain/subfolder
?
Upvotes: 1
Views: 615
Reputation: 143906
You need to add a specific rule to redirect, it needs to be before your routing rule. Try this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !subfolder/
RewriteRule (.*) /subfolder/$1 [L]
Upvotes: 2