Mark Locker
Mark Locker

Reputation: 891

Can ServerName match wildcards in the middle of a domain?

I'm trying to setup a server with two VirtualHost records like so:

<VirtualHost *:80>
    ServerName sub.domain.com
    DocumentRoot /path/to/dir/
    SetEnv FLAG false
</VirtualHost>

<VirtualHost *:80>
    ServerName sub.*.domain.com
    DocumentRoot /path/to/dir/
    SetEnv FLAG true
</VirtualHost>

I'd like the domain sub.domain.com to go through the first VirtualHost and a domain such as sub.test.domain.com to go through the second.

At the moment, the FLAG environment variable is always set to false, suggesting that sub.test.domain.com doesn't match the second one and so reverts to the first.

The only thing I can see being a problem is that the wildcard in the second ServerName directive is in the middle of the domain. Is this allowed or is something else the problem?

Upvotes: 1

Views: 280

Answers (1)

Jamie Kitson
Jamie Kitson

Reputation: 4140

You don't seem to be able to use wildcards in ServerName, use ServerAlias instead.

Upvotes: 1

Related Questions