Compressing URLs to make them shorter

This one time, I thought maybe I’d try compressing URLs to make the query strings shorter.

At some point, I thought I might try to compress long URLs to make them shorter. Like if you had a web application that used very long query strings, you could turn the list of name=value pairs into one compressed string that you’d then pass as PATH data. Ie: a URL like would become

Anyway, it was worth a shot but it becomes immediately obvious that it doesn’t work. Gzipping the query string will, of course, make it shorter, but that gives you a binary chunk and we need it to be text again before it can be put back in the URL. If we use uuencode or base64 to make it text again, we end up with a URL that’s bigger than the original in most cases. Not the desired result but it could be useful to obfuscate the query string contents a little bit. Obviously not the best way to do it, though.

Here’s the php proof that the idea wasn’t a good one, in case you want to fool around with it:
list($newurl,$qstr) = explode("?",$url);
$gz64 = base64_encode( gzcompress($qstr, 9) );
$newurl .= "/$gz64";

Try it with a URL here: