Michael Holland Michael Holland - 2 years ago 98
Apache Configuration Question

Apache VirtualHosts multiple ServerAliases with different TLDs

I am working with several domains which all follow a similar pattern of redirects. Instead of writing out each domain as it's own virtual host, I am attempting to make the file more maintainable using only one:

<VirtualHost *:80 *:443>
ServerName domain.xz
ServerAlias *.domain.xx *.domain.xy

RewriteEngine on
RewriteRule ^/(.*)$ https://xz.newdomain.com/$1 [QSA,NC,L,R=301]

In the above example domain.xx will redirect to xz.newdomain.com correctly however domain.xy will not. I have checked the documentation and cannot determine the reason that this does not work.

Is it possible to make this work as I intend or will I have to make them separate VirtualHost configurations?

kb0 kb0
Answer Source

You should add also second level domains names in ServerAlias, i.e:

ServerAlias domain.xx *.domain.xx domain.xy *.domain.xy
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download