With the introduction of the new “Revolution” release of the MODX Content Management System the developer team has implemented native support for serving multiple domains with one installation of the MODx software. Up to date such a constellation was only possible with workarounds and those so called solutions were not always 100% bullet proof under all aspects of web development.
In the following I have written a multiple domain tutorial for MODx Revolution and going with that I say thank you to Jason Coward (opengeek) who has supported my first multi-domain install and numberless other MODx topics with a lot of his “good open soucre energy”.
Diese Anleitung gibt es auch auf Deutsch.
The complete architectural redesign of MODx Revolution introduces under the keyword “contexts” the concept of encapsulating the elements of each website (or other elements) into a separate area in the MODx internal data structure – into a context.
After the basic installation of a MODx Revolution package the Manager looks as follows (I have added some example documents):
You see the default Context web which is always installed with MODx and the 3 documents “Start”, “MODx Revo … Tutorial” and “Error 404 page”.
If you now navigate to the overview of Contexts in MODx (Menu System > Contexts),
you can find 2 entries: web, the already mentioned default-Context for the first website and mgr, the MODx Manager that plays a special role and holds the MODx administrational backend.
To these Contexts we now add two more, one for each domain we want to serve additionally in the future. After the creation of the two additional Contexts the MODx-Manager looks like this
Now we furthermore add some standard documents to the Contexts, you need at least one start page/index page per domain/context and also one error page for each.
Names and descriptions are not important, we will only need the document IDs for the later completion of the Contexts configuration. After adding the documents for each of your domains the document structure should look similar to this
Contexts can be configured completely independent but in the first place they inherit all known website-settings from the base installation and hence we will (have to) change some of the Contexts’ parameters.
Open the Contexts view again via System > Contexts and what you will likely see is the view of Picture 3 above.
Right-click the Context you want to edit (I start with “thesearch”) and choose “Update Context” from the upcoming menu. The Context is now opened in the editing mode and you will have to switch to the “Context Settings” tab, then you will see the following
You now add, one after the other, the following configuration keys by clicking on Create new
key | value http_host | www.thesearchgoeson.com site_url | http://www.thesearchgoeson.com base_url | / site_name | MODxCMS TheSearchGoesOn test site_start | 6 error_page | 7 [optional, aber empfehlenswert] default_template | 3 [optional, wenn Sie mehrere templates vorbereitet haben]
Besides key & value you also have to fill out the field name in the dialog, there you can fill in whatever seems fitting and the other fields can stay as predefined or – where you like it – can be filled with additional descriptions. The values for site_start and error_page you can see in picture 4 or according to the settings on your web page.
When MODx finds an already existing value for the field name in the shipped language files, your manually added name might now be shown (and this behaviour might change in the future). After all settings/keys are done the Context parameters look as follows (sorted by key)
Repeat the last step for all domains/contexts you want to use, I have meanwhile also configured keys for the Context ffmwireless - and so we can proceed to the last step of this tutorial.
In the end follows a last simple step in the index.php file in your MODx root-directory (= thedocumentroot fo your webserver for this MODx installation), you can see the file contents here as originally shipped with MODx Revolution.
Delete or comment line 89
//$modx->initialize('web');
by adding the two slashes “//” in front and add the following code-block directly below the line, of course changed for your domain names and the number of domains you want to run with this MODx Revolution installation
/* setup for multiple domains */
switch(strtolower(MODX_HTTP_HOST)) {
case 'www.modx-templates.com:80':
case 'www.modx-templates.com':
// if the http_host is modx-templates.com, switch the context to web
$modx->initialize('web');
break;
case 'www.ffmwireless.de:80':
case 'www.ffmwireless.de':
// if the http_host is ffmwireless.de, switch the context to ffmwireless
$modx->initialize('ffmwireless');
break;
case 'www.thesearchgoeson.com:80':
case 'www.thesearchgoeson.com':
// if the http_host is thesearchgoeson.com, switch the context to thesearch
$modx->initialize('thesearch');
break;
default:
// by default / if no other rule can be applied, load 'web' context
$modx->initialize('web');
break;
}
After your code-block should only be the follwing lines from the original code
/* execute the request handler */
if (!MODX_API_MODE) {
$modx->handleRequest();
}
the complete new MODx indx.php file you can finde here (lines 91 – 112 have been changed).
That’s it, you made it – MODx is running with multiple domains and you can apply the tutorial for even more domains/contexts or other constellations!
Trackback URL for this post: http://www.h-quadrat.com/techblog/111-modx-revolution-multi-domain-context-installation-english.php/trackback
You must be logged in to post a comment.
[...] This document is also available in english. [...]
[...] This post was mentioned on Twitter by sharkbait and hquadrat, hquadrat. hquadrat said: @modxcms Multi domain installation tutorial with MODx Revolution http://is.gd/57zvx #MODx #MODxCMS #iworker [...]
[...] heck of a lot easier to do in Revolution. And it was; it took less than an hour to evaluate three different ways of running multiple virtual hosts, and settle on the one I liked the [...]