Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script is a simple script to redirect you from your site to other locations. It's a very basic short-link generator.

Redirector

This script is a simple script to redirect you from your site to other locations. It's a very basic short-link generator.

<?php
$base_url = "https://jon.sprig.gs";
$redirect = [
"@" => $base_url . "/t",
"+" => $base_url . "/g+",
"ak" => "https://gist.githubusercontent.com/JonTheNiceGuy/e1049f40b11c571eed61/raw/1be19fb3534e4c6d7f7e4a0720a27334973b0861/authorized_keys",
"d" => "https://joindiaspora.com/people/7f1771766a74695d",
"d*" => $base_url . "/d",
"fb" => "https://www.facebook.com/JonTheNiceGuy",
"facebook" => $base_url . "/fb",
"g+" => "https://plus.google.com/101307558846949684774",
"in" => "https://www.linkedin.com/in/jontheniceguy",
"key" => $base_url . "/pgp",
"now" => $base_url . "/blog/now",
"pgp" => "https://keybase.io/jontheniceguy",
"t" => "https://twitter.com/JonTheNiceGuy",
"twitter" => $base_url . "/t"
];
preg_match("&/([^/]*)/*&", $_SERVER['REQUEST_URI'], $matches);
if (isset($matches[1]) && isset($redirect[$matches[1]])) {
redirect($redirect[$matches[1]]);
} else {
redirect($base_url . "/blog");
}
function redirect($url) {
if (isset($_GET) && isset($_GET['test'])) {
echo "Because I got " . $_SERVER['REQUEST_URI'] . " I am Redirecting to $url";
} else {
header("Location: $url");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment