urlurl-shortenertinyurl

How does a URL Shortener work?


I wonder how a URL Shortener works, like how they extract the text from address bar and map it to correct URL, later redirect it. What programming language do they use? How do they maintain the history of the mapping? How do they ensure the uniqueness of the shortened url? How can a lay man unmap it without visiting the URL?


Solution

  • Wiki Is Your Friend

    Basically, a website with a shorter name is used as a place holder, such as bit.ly.

    Then, bit.ly generates a key for the user to provide, which is randomly generated to not repeat. With 35 character options and 8 or so values, do the math. That's a lot of possible keys. If a URL is equal to a previously existing key, I remember reading somewhere that they reuse keys as well.

    They don't really use a specific programming language, they just use a simple URL redirect, which can be done with HTTP response status code 301, 302, 307 or 308, depending.