I\'ve got a VirtualHost that looks something like:
ServerName domain1.com
ServerAlias www.domain1.com domain2.com www.domain2.com
You can have multiple VirtualHosts in a configuration file, so you should change your config to this:
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
ServerAlias www.domain2.com
</VirtualHost>
You can add another VirtualHost for each domain you want to do.
No need for rewrites.
<VirtualHost *:80>
ServerName domain1.com
ServerAlias domain2.com
... real vhost settings ...
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain1.com
Redirect permanent / http://domain1.com/
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.com
Redirect permanent / http://domain2.com/
</VirtualHost>
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.com
against the pattern www\.www.domain1.com
. These directives worked for me:
# Redirect www to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [L,R=301]