I’ve got a VirtualHost that looks something like:
<VirtualHost *:80> ServerName domain1.com ServerAlias www.domain1.com domain2.com www.domain2.com </VirtualHost>
When someone visits http://www.domain1.com/test, they should be redirected to:
domain1.com/test
When someone visits http://www.domain2.com/test, they should be redirected to:
domain2.com/test
My current RewriteRules are lacking.
Edit: Here’s what I’ve got so far:
# Rewrite www to non-www RewriteEngine on RewriteCond %{HTTP_HOST} www\.%{HTTP_HOST}$ [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
Obviously, this generates an infinite redirect loop.
Your RewriteCond is a bit wonky. I’m surprised it does anything at all, since it would seem to be trying to match the host
www.domain1.comagainst the patternwww\.www.domain1.com. These directives worked for me: