Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a URL Shortener work? [closed]

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?

like image 605
prap19 Avatar asked Dec 31 '10 23:12

prap19


People also ask

Is shortened URL permanent?

When you use these URL shorteners, the shortened links will always point to the URL you set it to on a permanent basis (as long as the URL shortener stays in service and never shuts down).

Why is Google Closing URL shortener?

The decision to shut down goo.gl and move to FDL is a result of changes in the ways that people share information online. In its effort to keep up with these changes, Google is moving to “smart URLs” that redirects users in a variety of ways that were not possible back in 2009. RIP Goo.gl URL shortener…

How long do URL shorteners last?

Bitly links never expire. If you use a custom domain to shorten your links they will continue to work as long as your DNS is still pointing at Bitly and the custom domain is attached to a Bitly account. While you can hide links and their analytics from the analytics view, the data will remain in Bitly.

How does URL shortener redirect?

URL shorteners work by creating a redirect to your long URL. Entering a URL into your internet browser sends an HTTP request to the web server to pull up a specific website. The long and the short URLs are both simply different starting points for an internet browser to get the same destination.


2 Answers

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.

like image 189
Daniel G. Wilson Avatar answered Oct 12 '22 23:10

Daniel G. Wilson


URL shortners just generate a shortcode, map the target URL to the shortcode, and provide a new URL. Visiting the URL performs a database lookup with the shortcode as a key, and redirects you to the target URL. There is no algorithmic association between a shortened URL and a destination URL, so you can't "unmap" it without going through the URL shortener's systems.

You can do it with any programming language and data store. Code generation is trivial to ensure uniqueness as well; if you had an incrementing primary integer key, you could simply encode the key as base62 and serve that. Since codes are incremental in nature, you'll never have a conflict.

like image 38
Chris Heald Avatar answered Oct 12 '22 23:10

Chris Heald