ИБ
$langkey = substr($_SERVER['REQUEST_URI'], 1, 2);
if($modx->context->get('key') != 'mgr'){
switch ($langkey) {
case 'en':
$modx->swichContext('en');
$modx->setOption('cultureKey', 'en');
break;
default:
$modx->switchContext('web');
$modx->setOption('cultureKey', 'ru');
break;
}
}
<?php
if ($modx->event->name != 'OnHandleRequest' || $modx->context->key == 'mgr' || !$modx->getOption('friendly_urls')) {return;}
$ctx = [
'ua'=>'web',
'ru'=>'ru',
];
$REQUEST_URI = explode('?',$_SERVER['REQUEST_URI'])[0];
if(preg_match('#^/assets/#',$REQUEST_URI, $matches)){
return;
}
$ctx_key = 'ua';
if(preg_match('#^/([a-z]{2})/#',$REQUEST_URI, $matches)){
$ctx_key = $matches[1];
} else {
$modx->switchContext('web');
return;
}
if(!isset($ctx[$ctx_key])){
$modx->switchContext('web');
return;
}
$context = $ctx[$ctx_key];
if ($ctx[$ctx_key] != 'web') {
$modx->switchContext($ctx[$ctx_key]);
}
else {
$context =$ctx_key;
}
$uri = str_replace('/'.$ctx_key.'/', '', $REQUEST_URI);
if ($uri != '') {
if ($res = $modx->findResource($uri,$ctx[$ctx_key])){
$modx->sendForward($res);
} else {
$modx->sendErrorPage();
}
} else {
$modx->sendForward($modx->getOption('site_start'));
}