I have a multi-site Drupal setup running on Apache on my Ubuntu slice. This works fine with a 1 to 1 mapping between host-name and Drupal site, for example:

  • host1.domain.com –> drupal/sites/host1.domain.com
  • host2.domain.com –> drupal/sites/host2.domain.com

But what if I want alias host names pointing to a single Drupal site? for example:

  • domain.com –> drupal/sites/domain.com
  • www.domain.com –> drupal/sites/domain.com
  • drupal.domain.com –> drupal/sites/domain.com

The method I’m currently using for my multi-site drupal on apache can not do the above.

After adding the ServerAlias to the apache config, that alias points to the “default” drupal site (drupal/sites/default).

Which makes sense, because Drupal probably just matches the host-name against the directory name. I wouldn’t want to do it another way either (like reading a config file, or a database, that’d be ugly).

A quick google didn’t return any obvious/definitive solutions.

So that leaves two options I can think of;

  • Rewrite the HTTP request - But what if I ever want Drupal to be aware of the different host-names?
  • Create a symbolic link to the site directory, so Drupal thinks there IS a directory for each host-name - Yep, that’s what I’ll do.
sudo ln -s drupal/sites/domain.com drupal/sites/www.domain.com
sudo ln -s drupal/sites/domain.com drupal/sites/drupal.domain.com

And this is what I’ll have:

  • domain.com –> drupal/sites/domain.com
  • www.domain.com –> drupal/sites/www.domain.com
  • drupal.domain.com –> drupal/sites/drupal.domain.com

Where www.domain.com and drupal.domain.com are symbolic links to domain.com.

Cool, it works, it’s tidy, easy to implement in my bash script (if I ever want to) :-)