Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Use Top-Level-Domain (TLD) Wildcard in Apache Virtual Host
Thursday - Oct 10th 2013 - by - (0 comments)

An Apache (2.2) virtual host can use wildcards for subdomains, as it is described on the official Apache documentation for Serveralias:

 The ServerAlias directive sets the alternate names for a host, for use with name-based virtual hosts. The ServerAlias may include wildcards, if appropriate.

In the example on the same page, the following VirtualHost section is shown:

<VirtualHost *:80>
ServerName server.domain.com
ServerAlias server server2.domain.com server2
ServerAlias *.example.com
UseCanonicalName Off
# ...

In this example a wildcard for all subdomains of example.com (*.example.com) is used.

But what if someone wants to use wildcards not only for a domain, but for a whole TLD, let's say for *.com?
I was surprised... it works!

For a testing scenario, I created two vhosts:

<VirtualHost *:80>
  ServerName ch.example.com
  ServerAlias *.ch
  DocumentRoot /home/www/ch

<VirtualHost *:80>
  ServerName fr.example.com
  ServerAlias *.fr
  DocumentRoot /home/www/fr

When I accessed "www.bla.ch" (just some fantasy domain name with the .ch tld and pointing to the web server's ip address), the correct index page was shown. The same happened, when I access www.bla.fr.

Setups like these can be helpful on a dedicated Apache web server for a multinational company, where each country has its own website.


Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6938 Days
until Death of Computers