Skip to content

Instantly share code, notes, and snippets.

/redirect.php
Created May 21, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.