photofloat/web/redirect.php

39 lines
1.6 KiB
PHP
Raw Normal View History

2011-05-07 02:09:07 +02:00
<?php
function cachePath($path) {
if ($path[0] == '/')
$path = substr($path, 1);
if ($path[strlen($path) - 1] == '/')
$path = substr($path, 0, strlen($path) - 1);
2011-05-07 04:48:09 +02:00
$path = str_replace('_-_', '-', str_replace('/', '-', str_replace(' ', '_', str_replace('(', '', str_replace(')', '', str_replace('#', '', str_replace('[', '', str_replace(']', '', str_replace('&', '', str_replace(',', '', str_replace('"', '', str_replace("'", '', strtolower($path)))))))))))));
2011-05-07 02:09:07 +02:00
while (strpos($path, "--") !== false)
$path = str_replace("--", "-", $path);
while (strpos($path, "__") !== false)
$path = str_replace("__", "_", $path);
if (strlen(path) == 0)
$path = "root";
return $path;
}
2011-11-16 07:11:28 +01:00
$url = str_replace("\b", "", str_replace("\r", "", str_replace("\n", "", $_SERVER["SCRIPT_URL"])));
2011-05-07 02:09:07 +02:00
if ($url[strlen($url) - 1] == '/')
$url = substr($url, 0, strlen($url) - 1);
if (strpos(strtolower($url), ".php") == strlen($url) - 4) {
$url = substr($url, 0, strlen($url) - 4);
$index = strrpos($url, "/");
2011-05-09 13:32:30 +02:00
$redirect = "/#!/".cachePath(substr($url, 0, $index))."/".cachePath(substr($url, $index));
2011-05-08 05:56:52 +02:00
} else if (strpos(strtolower($url), ".jpg") == strlen($url) - 4) {
$index = strrpos($url, "/");
2011-05-09 13:32:30 +02:00
$redirect = "/#!/".cachePath(substr($url, 0, $index))."/".cachePath(substr($url, $index));
2011-05-07 04:48:09 +02:00
} else if (strpos($url, "/cache/") === 0 || strpos($url, "/albums/") === 0 || strpos($url, "/img/") === 0 || strpos($url, "/img/") === 0 || strpos($url, "/js/") === 0 || strpos($url, "/css/") === 0) {
header("HTTP/1.1 404 Not Found");
exit();
2011-05-07 02:09:07 +02:00
} else
2011-05-09 13:32:30 +02:00
$redirect = "/#!/".cachePath($url);
2011-05-07 04:48:09 +02:00
header("HTTP/1.1 301 Moved Permanently");
2011-05-07 02:09:07 +02:00
header("Location: $redirect");
2011-05-09 13:32:30 +02:00
?>