Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2015 12:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e0e4d129e3b02747d7cd to your computer and use it in GitHub Desktop.
Save anonymous/e0e4d129e3b02747d7cd to your computer and use it in GitHub Desktop.
PHP 301 redirect script
<?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