Skip to content

Instantly share code, notes, and snippets.

@if0rest
Last active August 30, 2021 13:13
Show Gist options
  • Save if0rest/79213fd99db4be47f21b8f1e3ce035a6 to your computer and use it in GitHub Desktop.
Save if0rest/79213fd99db4be47f21b8f1e3ce035a6 to your computer and use it in GitHub Desktop.
Реализация редиректа PHP + TXT-файл
<?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