= Virtual Domain Behavior

(from http://theplant.jp/blog/2006/07/27/radiant-virtual-domain-plugin)

(modified by Brian Gernhardt for Radiant "mental")

Having decided to use Radiant on a new project consisting of 4 distinct websites for a client, we had the problem of either installing radiant 4 times, or coming up with a way to get it to support multiple websites.

Out of the box, Radiant is beautifully simple, but of course simplicity equals a reduced feature set. Radiant does however have a nice way of adding functionality called "page types". So after hacking away for a day or so, I was able to produce a plugin to handle virtual domains (having e.g. blog.theplant.jp, clients.theplant.jp instead of theplant.jp/blog or theplant.jp/clients). You can get it via subversion from http://theplant.jp/svn/code/radiant/plugins/virtual_domain.

As of the current version of Radiant, it requires a small patch to get working (included in the plugin). To install the plugin:

tar xzf virtual_domain.tar.gz
mv virtual_domain vendor/extensions
patch -p0 < vendor/extensions/virtual_domain/virtual_domain.patch

Once Radiant is patched, start radiant, go your admin screen and select the root page (the one at the top of the list) and change its page type to "Virtual Domain".

Once you do this, the front page of your website will be selected from the children, by trying to find a child whose page-slug is included in the host. For example if you have a child with a slug of "blog", and go to http://blog.theplant.jp, that child will be used as the root-page, and all of the Radiant tags that generate urls (<r:link/>, <r:url/> etc.) will draw the urls correctly.

If this isn't quite what you need, you can create a config part in the virtual-domain page, and add something like

blog.theplant.jp: articles
code.theplant.jp: development

i.e.
domain: slug

and the behaviour will use this slug to find the child. Of course you can add a default child with

*: <slug>

and then anytime someone accesses your site with a host that doesn't match any others in the config, it will use this page as the default. Enjoy!
