A script maintains a set of associations between local directories and their HTTP URLs. When invoked with the file or directory name, it returns the corresponding URL.
Another script was written as wrapper for this one; in addition, it keeps a local file with a database of the (sequentially assigned) IDs with a corresponding URL. The IDs are four-digit hexadecimal numbers, for simplicity.
Yet another script, this time PHP, when fed with the ID, checks the file, retrieves the ID, and returns the corresponding URL via 302 redirect. (Or dies with an error.)