Skip to content

Instantly share code, notes, and snippets.

@bdombro
Created May 23, 2014 15:42
Show Gist options
  • Save bdombro/bf3b96ddf627bd5d8c07 to your computer and use it in GitHub Desktop.
Save bdombro/bf3b96ddf627bd5d8c07 to your computer and use it in GitHub Desktop.
<?php
// Will parse queries and redirect appropriately
// Version 1.0
// Setup .htaccess to redirect certain links here
// Example: RedirectMatch /wiki* /legacy_file_redirect.php
if(isset($_GET["media"])) {
// handle http://dev.americanwhitewater.org/wiki/lib/exe/fetch.php?media=projects:gauley_project.jpg
$filename = explode(':',$_GET["media"])[1];
print "redirecting to $filename ... ";
header("HTTP/1.1 301 Moved Permanently");
header("Location: /sites/default/files/".$filename);
}
else {
print_r("Error: Did not recognize URL: ".$_SERVER["ORIG_PATH_INFO"]);
print_r("Expected a link like americanwhitewater.org/legacy_file_redirect.php?media=projects:1269.pdf");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment