This file contains 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
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule .* /canonical.php [L] | |
</IfModule> |
This file contains 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 | |
function not_found($message = '') { | |
header("HTTP/1.1 404 Not Found"); | |
echo $message."\n"; | |
die(); | |
} | |
if (!isset($_SERVER['REQUEST_URI'])) | |
not_found(); | |
$uri = htmlspecialchars($_SERVER['REQUEST_URI']); | |
if ($uri === '/canonical.php') | |
not_found(); | |
$dir = dirname(__FILE__).dirname($uri).'/'; | |
if (!file_exists($dir)) | |
not_found("{$uri} is not found."); | |
$file = pathinfo(basename($uri)); | |
$name = isset($file['filename']) ? $file['filename'] : ''; | |
$ext = isset($file['extension']) ? '.'.$file['extension'] : ''; | |
$filenames = array( | |
$name . strtolower($ext), | |
strtolower($name) . $ext, | |
strtolower($name) . strtolower($ext), | |
strtolower($name) . strtoupper($ext), | |
$name . strtoupper($ext), | |
strtoupper($name) . $ext, | |
strtoupper($name) . strtoupper($ext), | |
strtoupper($name) . strtolower($ext), | |
); | |
foreach ($filenames as $filename) { | |
if (file_exists($dir.$filename)) { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: '.dirname($uri).'/'.$filename); | |
exit(); | |
} | |
} | |
not_found("{$uri} is not found."); |