Multisite Support

Last updated on
18 October 2017

When you're operating Drupal in a single-domain environment, then all is nice and easy because when adding a new core, you're providing the URL in a form and DRD knows exactly to which end-point to talk to. Nothing to worry about.

However, if you're in a multi-site environment, where one Drupal core hosts more than one domain, then you have to give DRD a chance to recognize the domains that this core actually provides.

Just a note why this is something to consider for DRD and probably not so much for a regular web hosting setup. For the latter, you're configuring a web server (Nginx, Apache or the like) and tell them to which domains and ports they should be listening to and into which directory they should forward those requests. Drupal is then handling them and by different means knows from which directory to read the settings from. Each hosting company may have their own idea on how to structure that and where to store their settings. Some of them do that with environment variables, others in memory or they just use the Drupal default by using certain names for sub-directories in the /sites/ directory.

Now, using DRD you're coming the other way. You should imagine that you're looking inside the Drupal installation and want to find out, which domains are being hosted there. There are a couple of options which are described in the order of recommendation:

Provide the domain list in sites.php

This is the most forward and fully Drupal compatible way of doing this. Although Drupal 6 never supported the sites.php file, you can still use the same technique for DRD so that everything remains the same.

That file should be placed in the /sites/ sub-directory of your Drupal installation and contain a simple array declaration:

<?php

$sites = array(
  'www.example.com' => 'site1',
  'example.com' => 'site1',
  'www.mysite.com' => 'site2',
);

This example does several things:

  • There are three domains defined
  • The first and second one will find their settings in the site1 sub-directory and the second one is recognized as an alias for the first one
  • The third domain finds its settings in the site2 sub-directory and the alias without the leading www is not defined
  • If your webserver is sending requests into this Drupal installation for other domains, that are not mentioned in the sites.php file, they will find their settings in the default sub-directory

This even works with the Domain Access project, where totally different domains can share a database, not only the code base.

Just be as explicit as possible in your sites.php file. That way you don't leave anything for coincidence.

Use sub-directories only

If for what reason ever, it is not possible to maintain such a sites.php file, then DRD is checking all the sub-directories for the existence of settings.php files. For each sub-directory with a settings.php file in it, DRD assumes the directory name to be the domain name and then checks the settings.php file if there is a $base_url defined, which would then overwrite the directory name and use the defined base URL instead.

Please bear in mind that DRD is scanning the sub-directories this way only if the sites.php file is missing.

Help improve this page

Page status: No known problems

You can: