Skip to content

Instantly share code, notes, and snippets.

@MikSDigital
Forked from netProphET/subdomain-context.php
Last active August 29, 2015 14:26
Show Gist options
  • Save MikSDigital/98cbccd61a7e4e80ebda to your computer and use it in GitHub Desktop.
Save MikSDigital/98cbccd61a7e4e80ebda to your computer and use it in GitHub Desktop.
MODx Revolution plugin bound to OnHandleRequest event
<?php
/**
* plugin to map subdomain requests to contexts
* @setting event OnHandleRequest
* @todo currently, subdomains and context names are bound together.. remove this constraint through some mapping/lookup
* @todo currently, assumes first name in host (name before first dot) is what maps to the context
*/
$context = 'web';
$host = $_SERVER['HTTP_HOST'];
if(!empty($host)) {
$names = explode('.', $host);
if(is_array($names)) {
$subdomain = $names[0];
$modx->getContext($subdomain);
if(is_object($modx->contexts[$subdomain])) {
$context = $subdomain;
}
}
}
if($context !== 'web') {
$modx->switchContext($context);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment