Understanding the Virtual Site module

What the Virtual Site module does is basically 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.

Comments

-svs-’s picture

Followed these instructions, but cannot get it to work. I've set the condition, added the virtual site, but it still comes up as my main site.

any ideas? I'm running 10.6.2, mamp.

tbertin’s picture

I just did this and have got it changing, but no blocks appearing. Here is what I did differently than above:

* In the condition module, be sure the condition for your virtual site is listed above your main site.
* In the virtual sites module, be sure the new virtual site is listed above your main site.
* The theme tab didn't work for me in the virtual sites module, but this text in the variables tab did work:
theme_default=my_theme
admin_theme=garland

I'm guessing my third bullet is somehow the answer to my blocks not appearing, just don't know where to find the variables to use to set them to appear.

wabiloo’s picture

I've followed the example above to set up a virtual site, on the basis of pages with a path alias starting with subsite/.
However, I don't understand how I can create content for that subsite. In the "create content" form, there isn't anything (as far as I can see) that allows me to define what virtual site this content will be used in...

pnguyen’s picture

Looks like you should be using the same "Create Content" link sitewide, just that by specifying a path alias like subsite/my-new-page, VirtualSite will render the elements and settings you chose for the Virtual site called "subsite"

edumusic’s picture

I run cron and my problem was fixed.

hyperlinked’s picture

Removed... see my next comment for summary of my issue.

hyperlinked’s picture

If you're testing this out as a possible alternative to implementing a Drupal Multi-Site setup, be aware that if you've got directories setup for multi-site, you will run into some very maddening problems. I spent an entire day pulling my hair out trying to figure out why I could never get the correct theme and site information to show up. I thought I was messing up the conditions.

My problem was that some multi-site directories that I had setup earlier in the course of evaluating different approaches were getting precedence over the Virtual Sites module. If you've got directories setup for Multi-Site, remove them first or you'll go crazy trying to figure out why this module isn't doing what you expect it to do.

The conditions setup looks a bit confusing at first. The help text actually makes it more confusing. You might be better off ignoring the help text in the admin panel. I was completely thrown off by the word (not) showing up all over the rules. I thought it meant rules could only evaluate to true for conditions contained within evaluating to false. That is not the case. Conditions are triggered when the conditions you define are evaluated as true.

Also, it seems that the stable release suffers from a bug that prevents you from saving Site Information. If you always end up with the name of the main site as the Site Name, then you need to download the dev release.