Skip to content

Instantly share code, notes, and snippets.

@mspreij
Last active December 24, 2018 14:10
Show Gist options
  • Save mspreij/931b24a69810ce1293951544c8c78fc5 to your computer and use it in GitHub Desktop.
Save mspreij/931b24a69810ce1293951544c8c78fc5 to your computer and use it in GitHub Desktop.
<?php
$q = $_GET['q'];
$googStump = "https://www.google.com/search?q=";
$gooogle = $googStump.rawurlencode($q);
// custom keys
$keys = [
'hn' => 'https://news.ycombinator.com/',
];
if (isset($keys[$q])) {
$url = $keys[$q];
// custom key
}elseif (substr($q, 0, 2)==='g ') {
// force google (in case you're googling for something which is also a custom key)
$url = $googStump.rawurlencode(substr($q, 2));
}else{
// default to google
$url = $gooogle;
}
header("Location: $url");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment