Web design, programming, graphics, and pretty much anything else I care about.

Multisite using alias in Apache config

People are always having issues setting up a multisite using Drupal. Part of the hangup is working out the symbolic links you have to create. Why? At the heart of it, Apache needs to find the index.php in the root of the Drupal installation, regardless of what URL is used to access it.


It doesn't matter what address you are using, as long as you do something to point Apache to your index.php file. For some people this means using a symbolic link in your Drupal root, like so:

cd /var/ww/html/drupal_root
ln -s ../ site1

Now, when using the URL example.com/site, Apache will traverse the directory and end up in the drupal_root and thus, read the index.php file. After that, Drupal takes care of the rest.

This is fine with simple cases, but if you have a lot of sites, administration will be a hassle. It also makes it more difficult to version control your configuration. Instead, use the Alias directive. In the server config, usually /etc/httpd/conf/httpd.conf, or preferably, a new file in /etc/httpd/conf.d, add an Alias to your host configuration.

<VirtualHost *:80>
    DocumentRoot /var/www/html/drupal_root
    ServerName www.example.com
    ServerAlias example.com
    Alias /site1 /var/www/html/drupal_root

Now, your subsites will always work, regardless of what happens to your files directory. You can version control the config files, upgrade your Drupal software, perform disaster recovery, or whatever else you want.

The only caveat is that the Alias directive is for server config or virtual host only. You can not use it in a directory container or .htaccess file.