PHP
- 1 ответ
- 0 вопросов
1
Вклад в тег
AddEventHandler("main","OnProlog","checkUri");
function checkUri(){
$GLOBALS["STATUS"] = 200;
$uri = $_SERVER['REQUEST_URI'];
//обработка урла
if(strcmp($uri, $_SERVER['REQUEST_URI']) !== 0){
$_SERVER['REQUEST_URI'] = $uri;
$GLOBALS["STATUS"] = 301;
}
}
}
AddEventHandler('main', 'OnEpilog', 'сheck404Error', 1);
function сheck404Error() {
if ((defined('ERROR_404')) && (ERROR_404 == 'Y') && ($_SERVER['REQUEST_URI'] != '/404.php') || preg_match('/[а-яА-Я\s]+/msi', $_SERVER['REQUEST_URI'])) {
$GLOBALS["STATUS"] = 404;
}
}
AddEventHandler("main","OnEpilog","redirects");
function redirects(){
if($GLOBALS["STATUS"] === 301) {
header("HTTP/1.1 301 Moved Permanently");
header('Location: ' . $_SERVER['REQUEST_URI']);
exit();
} elseif($GLOBALS["STATUS"] === 404){
global $APPLICATION;
$APPLICATION->RestartBuffer();
include $_SERVER['DOCUMENT_ROOT'] . '/bitrix/templates/'.SITE_TEMPLATE_ID.'/header.php';
require ($_SERVER["DOCUMENT_ROOT"] . "/404.php");
include $_SERVER['DOCUMENT_ROOT'] . '/bitrix/templates/'.SITE_TEMPLATE_ID.'/footer.php';
}
}