I want to implement a URL shortener, with the need that people can customize the shorten url code.
In a simple url shortener, people get a messy code for a long url. But in some scenarios, one may want to customize or specify the short url to be more readable and self-explaining. For example, url.com/jimhome
rather than url.com/D3aK1
. This makes two parameters: the long url and the specifed short url. The system need to check whether the short url is used of course.
I have researched How to code a URL shortener? and find it good to use.
What's on my mind is: make 3 fields in DB, id, long url, short url. With a regular request without customization, do as the post does and store the generated short url.With a request with customization, first check existence, if not exist, insert the long url and short url, but this breaks the accordence between ID and short url. Is there a more elegant way?
I'm not native English speaker, if you got confused, please leave a comment. Thanks in advance.