ContextRouter Review

ContextRouter Review

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.

Contexts Drop Down Menu

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.

Create New Context

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.

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.

HTTP Host Context Setting

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.

Site Start Context Setting
TipTip: Even though we specified what to put in the Name field for each of these settings you can use any Name you wish, what needs to stay the same is the value in the Key fields.

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.

TipTip: Remember to clear MODX’s cache each time you create or edit a context setting to see your changes reflected.

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.

10 May
2013

Author Benjamin Marte Category Reviews Comments (4)

Comments (4)

  1. W. Shawn Wilkerson:
    May 14, 2013 at 09:04 AM

    An additional technique discussed in my book, is to create a skeleton base context with all of the settings and base pages created. Simply duplicate the context and make changes to the applicable settings (startpage, url, etc).

    I like the idea of a gateway plugin which does not require editing, though the system admin in me, would prefer to manually enter the domains, but I do have sites I can use CONTEXTROUTER on.

  2. Benjamin Marte:
    May 14, 2013 at 06:02 PM

    @Shawn that is why I always recommend to use ContextSettings since they act like global template variables. When hosting multiple sites ContextSettings are a life saver since all you need to do is create one site and duplicate the rest if setup correctly and ContextSettings play a major role in making that happen as you already know.

    ContextRouter does need to be configured for each site what you don’t have to do is a bunch of URL rewrites as it keeps some extras working across each Context which is an issue when hosting multiple sites on a single MODX installation.

  3. Ross:
    Jul 31, 2013 at 10:58 PM

    Hi I am trying to set up multiple top level domains.


    Currently otherdomain.com (context:other) just redirects to maindomain.com (context:web)


    I am using virtual hosts on my server all pointing to the same modx install on maindomain.com. Any tricks to the server set up for this to work?


    MODX Revolution 2.2.8-pl (traditional) - FURL on


    Thanks

  4. Benjamin Marte:
    Aug 01, 2013 at 06:56 AM

    Are you using this method or did you try doing it manually first? If you did anything manually you have to undo all that and use ContextRouter and make sure you add the other ContextSettings I recommend at the end of the tutorial it will help to better debug your situation.

    Good Luck.


Leave a Comment

This thread has been closed from taking new comments.


Scroll to top