0

I have an Apache server with multiple sites using their own domains. For one of those sites I wish to have wildcard subdomains.

I have set up the domain records for *.example.com and it works just fine.

With this I can configure any subdomain (e.g. abc.example.com) to point to any site, as long as I specify the subdomain name.

The wildcard domain though (*.example.com) ends up on the site that is configured in /etc/apache2/sites-available/default instead of the site that has ServerName *.example.com.

What did I do wrong?

*.example.com

<VirtualHost *:80>
    ServerName *.example.com
    ServerAlias abc.example.com

    DocumentRoot /var/www/example
    <Directory /var/www/example>
        AllowOverride all
        Options -MultiViews
        Allow from all
    </Directory>
</VirtualHost>

default

<VirtualHost *:80>
    ServerName default.com
    ServerAlias www.default.com

    DocumentRoot /var/www/default/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/default/>
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
Christoffer
  • 257
  • 4
  • 11

1 Answers1

1

Try switching the ServerName / ServerAlias-directives like this:

ServerName abc.example.com
ServerAlias *.example.com

As far as I know, wildcards only work with the ServerAlias directive.

Kvisle
  • 4,193
  • 24
  • 25