Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?


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

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


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

    DocumentRoot /var/www/default/
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/default/>
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
Thanks, it was that easy :) –  Christoffer Oct 29 '11 at 12:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.