Commit baa17091 authored by Olga's avatar Olga

Merge branch 'feature/redirects'

parents 6d378f0f 6aa855ab
<?
$needRedirect = false;
$statusCode = 301;
$statusMessage = "Moved Permanently";
$fullUrl = $_SERVER['REQUEST_URI'];
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'HEAD')) {
//Исключить админку
if (substr($url, 0, 8) === '/bitrix/') {
return;
}
//Редирект со знака вопрос
if (substr($fullUrl, -1) === '?') {
$needRedirect = true;
$new_url = str_replace('?', '', $fullUrl);
}
//Редирект много слешей
if(preg_match('#//#', $fullUrl)){
$needRedirect = true;
$new_url = preg_replace('/(\/+)/','/', $fullUrl);
}
//Редирект на слеш
if (substr($url, -1) !== '/' && !pathinfo($fullUrl, PATHINFO_EXTENSION)) {
$needRedirect = true;
$new_url = $url . '/';
}
if ($needRedirect) {
header("Location: //{$_SERVER["SERVER_NAME"]}{$new_url}", true, $statusCode);
header("Status: {$statusCode} {$statusMessage}");
exit;
}
}
<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
if (file_exists(__DIR__ . '/include/redirects.php')) {
require_once(__DIR__ . '/include/redirects.php');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment