In this review we will talk about ContextRouter the extra that will make hosting multiple sites or subdomains on a single MODX install breeze.
It’s no secret you can host multiple sites or a subdomain on a single MODX installation but setting these up manually is not as straight forward as you might think, don’t believe me? Check out fellow MODX’er Aaron (Belafonte) Baxter’s tutorials for setting up multiple top level domains and multiple subdomains in MODX.
Ok, now that you’re back I’m going to show you how you can accomplish the same thing with ContextRouter by adding a few simple context settings, ContextRouter is yet another MODX extra developed by the genius Mark Hamstra so if you use it or any of his other extras be sure to support him by making a small donation if you can. Also make sure to sign up to the ModMore newsletter, another project by Mark where you will be able to buy premium MODX extras that will be launching soon.
Before we begin you should already have the url of your domain or subdomain pointing to your MODX installation in your control panel, ContextRouter will take care of the rest.
With all that out of the way let’s get to the good stuff, so you download and install ContextRouter via the MODX Package Manager once the installation is done you’re ready to start using it. How do we use it? Easy, First we need to create a new Context. Hover over your System menu then click on the Contexts drop down selection, this will take you to the Context Manager page.
Once in the Context Manager click on the Create New button, this will open a popup where you can specify the name of your context and the description in the appropriate fields.
Now that you created your context we are almost done (toldja it was easy), now click on your contexts name in the File Tree Navigation on the left, this will take us to the Context Properties page.
In order to get ContextRouter working all we need is a minimum of 2 settings mainly HTTP Host and Site Start, let’s create them by clicking on the Context Settings Tab, then click on the Create New button. The first setting we are going to create is the HTTP Host, in the Key field we need to put http_host, in the Name field we are going to put HTTP Host, we are going to put a brief description of what this setting is for in the Description field and in the Value field we are going to put the URL of our site or subdomain.
The next setting we need to create is the Site Start setting so ContextRouter knows what resource is the index for our context, repeat the same steps we did to create our first setting but this time we will use the following settings: in the Key field we will put site_start, in the Name field we will put Site Start and in the Value field we will put the ID of the resource that will be the index of our context in this example the ID is 9 click save to finish.
Now go to the url of your site or subdomain and you should see the content of the resource you selected as the Site Start setting.
Another benefit of using ContextRouter over the manual method is that it allows your site to access any folder in your MODX installation without having to do any URL rewrite rules which can be very tedious when dealing with some extras.
Although we only used 2 settings to setup our second site I recommend you make a few other settings, mainly error_page, site_name, site_url, http_hosts_aliases if using more than 1 url for the same site or subdomain and base_url. All of these are created using the same steps we used to create the http_host and site_start.
If you never heard of ContextRouter I hope this post changed that and showed you the benefits of using it when hosting multiple sites on a single MODX installation. Good Luck and happy MODX’ing.