Meloman
Meloman

Reputation: 3712

Apache virtualhost : a specific host (subdomain) for all domains

I have a configuration accepting many domains on a production server (filtered by a proxy upstream). This Apache conf accepts all domains on 80 port and calls /var/prod/ as DocumentRoot.

What I want is to redirect all beta subdomain only (http://beta.domain1.ch, http://beta.domain2.ch, http://beta.domain3.ch, ...) for every domains to /var/beta/ DocumentRoot folder.

Is it possible with a mask in virtualhost tag like the following?

<VirtualHost beta.*:80>

Or do I need to put all my domains in ServerAlias ?

<VirtualHost *:80>
    DocumentRoot        /var/beta/
    VirtualDocumentRoot /var/beta/
    ServerAlias         beta.domain1.ch 
    ServerAlias         beta.domain2.ch
    ServerAlias         beta.domain3.ch
    ServerAlias         beta.domain4.ch
    ...
</virtualhost>

<VirtualHost *:80>
    DocumentRoot        /var/prod/
    VirtualDocumentRoot /var/prod/
    ServerAlias         *.domain1.ch 
    ServerAlias         *.domain2.ch
    ServerAlias         *.domain3.ch
    ServerAlias         *.domain4.ch
    ...
</virtualhost>

Thanks for help

Upvotes: 1

Views: 886

Answers (1)

Meloman
Meloman

Reputation: 3712

As VirtualHost and serverNname doesn't accept wildcard, actually serverAlias does. This is working for me :

<VirtualHost *:80>
    ServerName          beta-server.main-domain.com
    ServerAlias         beta.*
    DocumentRoot        /var/beta/
    VirtualDocumentRoot /var/beta/
</virtualhost>

<VirtualHost *:80>
    ServerName          prod-server.main-domain.com
    ServerAlias         www.*
    DocumentRoot        /var/prod/
    VirtualDocumentRoot /var/prod/
</virtualhost>

Working on Apache 2.2, I need to test it on 2.4.

Upvotes: 2

Related Questions