Created
May 21, 2015 12:21
-
-
Save anonymous/e0e4d129e3b02747d7cd to your computer and use it in GitHub Desktop.
PHP 301 redirect script
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 | |
/** | |
* PHP Redirect Script | |
* | |
* @author http://johnmorrisonline.com | |
*/ | |
// Map IDs to URLs | |
$accepted_ids = array( | |
'goog' => 'http://www.google.com', | |
); | |
// Die on no ID | |
if ( !isset( $_GET['id'] ) ) { | |
die('Oops. Need an ID'); | |
} | |
// Set ID | |
$id = $_GET['id']; | |
// Die on ID not supported | |
if ( ! in_array( $id, array_keys( $accepted_ids ) ) ) { | |
die('Oops. That ID is not supported.'); | |
} | |
// Get campaign if set | |
if ( isset( $_GET['utm_campaign'] ) ) { | |
$campaign = $_GET['utm_campaign']; | |
} | |
// Create redirect | |
$redirect = sprintf('%s?q=%s', $accepted_ids[$id], $campaign); | |
// Run the redirect | |
//echo $redirect; | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Location: {$redirect}"); | |
// Exit | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment