Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
$407 per month—let's make that $500!Learn more
ContextRouter is a plugin by Mark Hamstra which can be used to route contexts based on domains or subdomains. You can not route subfolders with ContextRouter.
Installation & Configuration¶
Simply install ContextRouter through package management or from the MODX Extras site. There's no manager component or configuration you need to manage, however ContextRouter does depend on your individual contexts being configured properly and it has several system settings you can enable if needed.
For ContextRouter you will at the very least need each context you want routed to have a http_host context setting. This should contain the host used to access the context, for example "sub.domain.com" or "otherdomain.tld". If you want multiple hosts to route to the specific context, you can specify them as a comma separated list in a http_host_aliases context setting.
For MODX to properly function, you'll also want to define the base_url (eg "/"), site_url (eg http://sub.domain.com/) and site_start (eg 15 for resource 15) settings.
If you already had these configured when you installed ContextRouter, it should automatically fetch these the first time you make a front end request. If you are configuring these settings after installing ContextRouter, you may have to hit Site > Clear Cache to ensure it is collecting them.
Go to System > System Settings and choose contextrouter in the namespace dropdown (the one that defaults to "core").
|contextrouter.includeWww||When enabled, ContextRouter will automatically alias www and no-www variations of a host to the current context.|
|contextrouter.defaultContext||The key of the context that any hosts that are not specifically routed should be routed to.|