Created
August 23, 2017 14:57
-
-
Save Semdevmaster/e128b6ad630d385fb12b90a45202d2f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
создаём плагин на событие - OnHandleRequest | |
<?php | |
if ($modx->event->name != "OnHandleRequest" || $modx->context->key == 'mgr') { | |
return; | |
} | |
if ($_SERVER['REQUEST_URI'] != '/') { | |
if(substr($_SERVER['REQUEST_URI'], -1) === '/'){ | |
$new_url = preg_replace("#/$#", "", $_SERVER['REQUEST_URI']); | |
$modx->sendRedirect('http://'.$_SERVER["SERVER_NAME"].$new_url,array('responseCode' => 'HTTP/1.1 301 Moved Permanently')); | |
} | |
$R_URI=substr($_SERVER['REQUEST_URI'], 1); | |
if ($R_URI === 'index.php') $modx->sendRedirect('http://'.$_SERVER["SERVER_NAME"],array('responseCode' => 'HTTP/1.1 301 Moved Permanently')); | |
if ($R_URI === '/') $modx->sendRedirect('http://'.$_SERVER["SERVER_NAME"],array('responseCode' => 'HTTP/1.1 301 Moved Permanently')); | |
$uri = strtok(substr($_SERVER['REQUEST_URI'], 1), '?'); | |
if ($uri == 'index.php') { | |
$uri = intval(str_replace('/index.php?id=', '', $_SERVER['REQUEST_URI'])); | |
//не уверен, нужна ли здесь проверка на наличие ресурса, т.к. в случае отсутствия оного, событие должно перехватить OnPageNotFound | |
if(empty($uri)) { | |
$url = 1; | |
} | |
$modx->sendRedirect($modx->makeUrl($uri), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment