I have written a PHP encode/decode bijective function that simply takes a number and encode/decodes it with base-58 with a custom alphabet.
This shortener works fine, but I want to be able to restrict certain words and have the ability to create custom vanity urls.
This should mean that the user will not get their link reloved to domain.com/ boobs or something.
Also I want to be able to have domain.com/stackoverflow resolve to domain.com/12342 without disrupting the bijective function.
PROPOSED SOLUTION
I had a couple proposals but they dont seem optimal. One way I thought of doing it is storing the custom urls in the database so 1234 => mycoolurl and then upon encode/decode, lookup to see if it already exists. if it does, offset the number by like 10,000,000 (so it would become 10,001,234 and then encode/decode it. This makes some links much longer than others and sets a hard limit at 10,000,000 links (which is practically ok, but still not very elegant). To solve the curse words issue, I can insert dummy links in the DB.
I'd love to hear your input!