Today I used a url shortener bitly in order to send a short link to my friend. However I asked a question: How does this mechanism functions? Given a link like that: google.com/search
I think that the bitly service will generate a code for this link to be something like this: bit.ly/2GWhfPZ
So a new link with an ID '2GWhfPZ' corresponding to the given link will be stored in the database (if it will exists)
But when I put the generated link into a browser, how does the browser map the generated bitly link with the real one and returns the result?
Bitly maintains a table of short id and long url. When you enter bit.ly/2GWhfP, the request is sent to bitly server. The server parse the url to get the short id. It looks for the id in db to get real url. Server then respond back with a 301 redirect status and redirect url. Browser redirects to that url.
Normal response to browser from server will be 200. It tells browser to render the html. 300 tells browser to redirect. 404 - not found. 500 internal server error. Research on http status codes
Read my blog post - Create your own private url shortener for free coffeencoding.com/how-to-create-your-own-private-…
it does not, it's a simple redirect :). The browser may or may not do a prefetch and resolve it. But in the end it's just a simple http status code and target address.
Tuncay Üner
Software Craftsman
It reminded me question "what is a panzerschreck?"
The answer was "it schrecks panzers" indeed. :)
maybe following image give you an idea how does url shortener redirects to origin url.