[H-GEN] Multiple Domains - Apache

Menno Smits menno at freshfoo.com
Tue Apr 29 09:11:34 EDT 2008


Sarah Walters wrote:
> You can't do this from within the virtualhost stanzas, because 
> www.domaina.com <http://www.domaina.com/> is a DIFFERENT virtual host 
> from domaina.com <http://domaina.com/>. It appears to be defaulting to 
> the first virtualhost and always hitting that rewrite rule (which is a 
> bit strange).

This is correct. The rewrite rule for domainb doesn't get triggered 
because the ServerName for the domainb VirtualHost doesn't match the 
hostname when the request is for http://domainb.com/. The request is 
then handled by the default (first) virtualhost.

 > What you need to do instead is create virtual hosts for the non-www
 > domain names and set them to redirect to the www virtualhosts.

You can avoid the need for extra VirtualHosts by using ServerAlias. 
Something like:

<VirtualHost *>
    ServerName www.domaina.com
    ServerAlias domaina.com
    ...
    (Rewrite domaina.com to www.domaina.com)
</VirtualHost>

<VirtualHost *>
    ServerName www.domainb.com
    ServerAlias domainb.com
    ...
    (Rewrite domainb.com to www.domainb.com)
</VirtualHost>

Hope that helps,
Menno




More information about the General mailing list