kenzabukuro on Twittter

Using multiple TLD subdomains with the same virtual host entry in Apache

Yesterday I was looking for a way to simplify subdomain entries in Apache's virtual hosts when I tried something I couldn't find in the documentation:

    <VirtualHost 1.2.3.4:80>
        ServerName sub.domain.*
        ...
        DocumentRoot /path/to/some/stuff
        ...
        <Directory "/path/to/some/stuff">
            Order deny,allow
            Allow from all
            Allowoverride all
        </Directory>
        ...
    </VirtualHost>

It just works. So point multiple domains with different TLDs at that IP address, and Apache will serve content for them all from the same source folder. Now start thinking what can be done with aliases from here...

*This works on Apache 2.2.x - as you can see from the "Allowoverride all" statement. I've not had a chance to try on Apache 2.4, so holler at me if you do.