So I used to, like many, use Chrome search engine entries without
a %s as url bar aliases. I had many of them. Then Google decided
to break that functionality. Search engines with %s still work,
so I configured the a search engine to redirect to a simple
.php script, the core of which is here:
// ... stuff like checking the user is authorised
$aliases = [ ];
if( ! file_exists("aliases.txt") ) {
http_response_code(500);
echo "no aliases";
exit();
}
$a = file_get_contents("aliases.txt");
$lines = explode("\n",$a);
foreach($lines as $line) {
# anything beyond the first two nonwhitespace entities
# are silently discarded (urls never have spaces)
$line = trim($line);
if( preg_match('/^#',$line) {
continue;
}
$xs = preg_split('/\s+/',$line);
if( count($xs) == 1 ) {
continue;
}
$aliases[$xs[0]] = $xs[1];
}
$qs = $_SERVER["QUERY_STRING"];
$qs = urldecode($qs);
$qs = trim($qs);
$qs = preg_replace('/\s+/','.',$qs);
if( array_key_exists($qs,$aliases) ) {
$url = $aliases[$qs];
header('Location: '.$url, true, 303);
exit();
}
// do whatever for blank query string or not found...
All you need is a file of the form
# youtube
and https://www.youtube.com/@andthatsmytune
# bbc
ip https://www.bbc.co.uk/iplayer
and then e.g. typing a and into the url bar takes you here.
So it's only costing me two extra keypresses each time.
How you edit this file is up to you: all in, with editing and viewing code together, it's a little under 500 lines of PHP, HTML, Javascript, and CSS combined.
Very much a quick bodge I wrote for myself in an hour when a Chrome update broke the aliases I was using (took me a while googling around to find out why Chrome was misbehaving).