I believe bit.ly performs a hash and then base64 encodes the result. You can do the same, although it will be more than 4 characters. Be sure to add code that processes hash conflicts. You can add 1, 2, 3 etc. when the first hash is used.
Another approach is to create a new table in the database. Each time you need a new URL, add a row to this table. You can use PK as the URL value. This will give you up to 10,000 unique values using only four characters. Base64 is encoded even more.
source
share