Created
December 25, 2011 14:07
-
-
Save rodneyrehm/1519311 to your computer and use it in GitHub Desktop.
URL-Rewriting: Peter Kröner
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
RewriteEngine on | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_URI} !^/excluded-directories-like-css-or-js/ | |
RewriteRule ^(.*)$ not-found.php [QSA,L] |
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 | |
$redirect = array( | |
'/old-1.html' => '/new-resource-1.html', | |
); | |
$uri = explode('?', $_SERVER['REQUEST_URI'], 2); | |
if (isset($redirect[$uri[0]])) { | |
// could do some funky RegEx or DB-lookups here, too :) | |
$go = $redirect[$uri[0]]; | |
if (!empty($uri[1])) { | |
$go .= '?' . $uri[1]; | |
} | |
header('Moved Permanently', true, 301); | |
// Note: may want to add https?://domain "required" by HTTP/1.0 - but not a *single* browser cares | |
header('Location: '. $go); | |
// Note: exit; would kill a fastcgid's process for no reason | |
return; | |
} | |
header('Not Found', true, 404); | |
// do your funky 404 business |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment