Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
f6ba0d2174
470 files changed
+26454
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jinove\Vinoteca;
|
||||
|
||||
class Routing
|
||||
{
|
||||
private const MOVED = ["news" => "articles"];
|
||||
|
||||
public static function onPageStart(): void
|
||||
{
|
||||
if (defined("ADMIN_SECTION") || PHP_SAPI === "cli" || !in_array($_SERVER["REQUEST_METHOD"] ?? "", ["GET", "HEAD"], true)) {
|
||||
return;
|
||||
}
|
||||
$uri = (string)($_SERVER["REQUEST_URI"] ?? "");
|
||||
$path = (string)parse_url($uri, PHP_URL_PATH);
|
||||
$query = (string)parse_url($uri, PHP_URL_QUERY);
|
||||
if ($path === "" || preg_match('#^/(bitrix|upload|local|include)/#', $path)) {
|
||||
return;
|
||||
}
|
||||
if (str_contains(basename($path), ".")) {
|
||||
return;
|
||||
}
|
||||
$target = str_contains($path, "%") ? $path : mb_strtolower($path);
|
||||
if (preg_match('#^(/(?:ru|pl))?/(' . implode("|", array_keys(self::MOVED)) . ')(/.*)?$#', $target, $match)) {
|
||||
$target = $match[1] . "/" . self::MOVED[$match[2]] . ($match[3] ?? "/");
|
||||
}
|
||||
if (!str_ends_with($target, "/")) {
|
||||
$target .= "/";
|
||||
}
|
||||
if ($target !== $path) {
|
||||
LocalRedirect(Config::host() . $target . ($query !== "" ? "?" . $query : ""), true, "301 Moved permanently");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user