Creating a Subdomain from a Folder using Virtual Hosts

This tutorial will demonstrate how to use a Context to create and manage a separate subdomain in a single Revolution install. We're going to create a subdomain at dev.modxcms.com (of course, not really, but you get the idea).

Creating the Context

Navigate to System -> Contexts. Click Create New to create a new context. Give it a name of "dev" and click Save.

Next, in the Resource Tree (to the left) create a "Dev Home" Resource. Place it in the root of the "dev" context. Also, while you're at it, create a "Dev Docs" Resource as well with an alias of "documentation". We'll use this to test our context links.

Your tree should look something like this:

From there, go ahead and right-click on the "dev" Context in the tree, and click "Edit Context". From here we'll see a Context Settings tab. Click on it, and you'll need to add a few settings:

base_url - Set this to "/" (no quotes) since we're making the root of the URL our base.

You can add other context-specific settings, such as error_page, unauthorized_page, cultureKey, and others if you so choose. All system settings can be overridden by setting them on a context.

Note: LINKING BETWEEN CONTEXTS
If you're going to be linking back to the 'web' context from this context ('dev'), you'll want to add those same Context Settings (with 'web'-specific values, of course) to the 'web' context. This allows MODx to know where to redirect 'web' context URLs back to.

After creating the settings, clear your site cache.

Creating the Virtual Host

cPanel Users
cPanel will make the necessary changes automatically when you create a new sub domain. Manually editing the Virtual Hosts is not recommended.

Now we need to do some Apache work. (If you're not using Apache, you can at least follow the same idea and customize it to your server.) Go to Apache's httpd.conf file, and add these lines, changing where necessary for your domain name: