Multisite Drupal with clean urls in subdirectories

Today, I was assigned a task to setup a new website as fast as possible. I’m not a web designer. I just know the contents. Fortunately, I have a Drupal already installed as intranet site. Anyway, it is just an intranet site so it is located in subdirectory of the main web, says http://www.sample.com/intranet. And then I would like to have http://www.sample.com/conf2006. I cannot use the same database of intranet because the intranet is completely private site. I don’t want anyone to read my secret contents. So I decided to use multisite feature officially provided by Drupal. As a result, I have 3 sites as follows.

  • www.sample.com.intranet
  • www.sample.com.conf2006
  • www.sample.com

It works fine as long as I disable Clean URLs. However, I like to use Clean URLs in all sites. At this point, I have to use some tricks. If you notice a line in .htaccess, you will see the RewriteBase directive. This is the key that prevents Clean URLs to work in multisite configuration with subdirectories. You are allowed to specify only one base URL. In other words, only one subdirectory multisite will work correctly. Anyway, I don’t want to make a copy of all codes. So, I solved this problem by below instructions.

  1. Place the drupal code at /var/www/drupal
  2. Setup all sites in /var/www/drupal/sites as usual
  3. Make directories at /var/www/intranet and /var/www/conf2006
  4. Create symbolic links in intranet and conf2006 to all files and directories in /var/www/drupal
    cd /var/www/intranet
    ln -s ../drupal/* .
    cd /var/www/conf2006
    ln -s ../drupal/* .
  5. Copy .htaccess to intranet and conf2006 and then specify the correct RewriteBase

That’s all. Now you can maintain only a single instance of Drupal for 3 sites with clean urls in subdirectories.

Technorati Tags: , , , , , ,

Post new comment