Before I came across this thread, I struggled with getting context routing for domains to work. The solution I came up with was to edit the index.php file in the root directory of the MODx install.
I replaced the lines:
/* Initialize the default 'web' context */
$modx->initialize('web');
with:
/* start context mapping */
$webDomain = $_SERVER['HTTP_HOST'];
if ($webDomain == 'domain1.ext') {
// if the http_host corresponds to domain1.ext, switch to the context you want to for that domain
$modx->initialize('Context1Name');
} else if ($webDomain == 'domain2.ext') {
// if the http_host corresponds to domain2.ext, switch to the context you want to for that domain
$modx->initialize('Context2Name');
} else {
// fallback, go to the main context
$modx->initialize('web');
}
/* end context mapping */
Seems to route fine, then ensuring that the context has the context settings (site_name, base_url, error_page, http_host, site_start, site_url, default_template) configured.
Everything seems to work well and does not add the load of having to process anything extra in MODx, now I don't know if I will later run into problems with this method or not.
- Perhaps @Zaigham or someone could clarify, should I remove this method and use the ContextRouter instead?
- Also, I am having a problem with my template for the non-web contexts where the [[++site_name]] value pulls the Site Name from the web context instead of the initialized context. Any ideas here?
- Will using this method cause me problems with snippets/extras/add-ons going forward?
[ed. note: siteleas last edited this post 12 years, 11 months ago.]