Last active
August 30, 2021 13:13
-
-
Save if0rest/79213fd99db4be47f21b8f1e3ce035a6 to your computer and use it in GitHub Desktop.
Реализация редиректа PHP + TXT-файл
This file contains hidden or 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
<?php | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
error_reporting(E_ALL); | |
$redirects = array(); | |
$file = file(__DIR__ . DIRECTORY_SEPARATOR . 'redirect.txt'); | |
foreach ($file as $row) { | |
list($src, $target) = explode(' ', trim($row)); | |
$redirects[$src] = $target; | |
} | |
$need = $_SERVER['REQUEST_URI']; | |
if (array_key_exists($need, $redirects)) { | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Location: " . $redirects[$need]); | |
exit(); | |
} | |
/* | |
redirect.txt | |
--- | |
/shop/ http://shaluny.ru/ | |
/catalogue/shop/ http://shaluny.ru/ | |
/catalogue/shop/product/ http://shaluny.ru/ | |
/catalogue/shop/product/3189/ http://shaluny.ru/ | |
*/ | |
// EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment