Skip to content

Instantly share code, notes, and snippets.

@rodneyrehm
Created December 25, 2011 14:07
Show Gist options
  • Save rodneyrehm/1519311 to your computer and use it in GitHub Desktop.
Save rodneyrehm/1519311 to your computer and use it in GitHub Desktop.
URL-Rewriting: Peter Kröner
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/excluded-directories-like-css-or-js/
RewriteRule ^(.*)$ not-found.php [QSA,L]
<?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