Friday, February 26, 2010

URL Shortening

Every long URL is associated with a key, which is the part after http://domain.tld/. For example has a key of m3q2xt.

There are several techniques to implement a shortening.

Keys can be generated numerically in base 36 assuming 26 letters and 10 numbers. The keys in order would be 0, 1, 2, ..., 9, a, b, ..., z. If uppercase and lowercase letters are accepted then the number should be in base 62 (26 + 26 + 10).
A hash function can be made or a random number can be generated so that key sequence is not predictable.
Users can propose their own keys. For example, can be shortened to