Setting up a virtual site

Last modified: April 25, 2008 - 04:15

Understanding the Virtual Site module

What the Virtual Site module does is basicly overriding Drupal settings. This is also what Drupal's multi-site feature does at core-level (bootstrap), but than at run-time level (hook_init()). This difference is why Virtual Site cannot change database settings, because these are already initialized when Virtual Site comes in.

Understanding a single Virtual Site

Each Virtual Site you create can be seen as a group of settings to override Drupal settings with. To determine when which Virtual Site settings are applied, the module depends on the Condition module. A condition can be seen as a group of requirements. When all requirements are met, the condition is TRUE.

A real-life example

Let's say I want to have a different theme and site title for all pages that have a path alias starting with subsite/.

  • Install both the Virtual Site and the Condition module.
  • Go to admin/settings/condition/add and choose a name.
  • Expand Requirement: Pages, set Validate to Only... and enter subsite/*.
  • Press Save settings.
  • Go to admin/build/sites/add and choose a name.
  • Set Criteria to When ANY selected condition is met.
  • Check the newly created condition and press Save settings.
  • Find the newly created virtual site in the list and click the edit link.
  • Go to the Information tab, change the default site name and press Save settings.
  • Go to the Theme tab, select a theme and press Save settings.
  • Optionally, change any theme settings and press Save settings.
  • Create or go to a page having an alias starting with subsite/.

Handling multiple (sub)domains with Virtual Sites

Just like with Drupal's multi-site feature, the key is to point all the (sub)domains to the main public HTML directory. You can ask your host to point all domains to the same public HTML directory or use symbolic links. Once set, you can create a new condition for every domain and use the hostname requirement to enter the domain you want the condition to be valid for.

 
 

Drupal is a registered trademark of Dries Buytaert.