How does Link Shortening Works

How does Link Shortening Works

22.Dec.2021

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 his.. .

Short URL  The URL shortener on Meta-Wiki URL shortening is a technique on the World Wide Web in which a Uniform Resource Locator (URL) may be made substantially shorter and still direct to the required page. This is achieved by using a redirect which links to the web page that has a long URL. For example, the URL pleassets/category_B/subcategory_ can be shortened to  and the URL URL_shortening" examan be shortened to "  Often the redirect domain name is shorter than the original one. A friendly URL may be desired for messaging technologies that limit the number of characters in a message (for example SMS), for reducing the amount of typing required if the reader is copying a URL from a print source, for making it easier for a person to remember, or for the intention of a permalink . In November 2009, the shortened links of the URL shortening service Bitly were accessed 2.1 billion times.

A:

It's not really a question of programming languages but rather of data structures.

The first step is to determine what kind of information you want to store about your URLs. You could simply have an array with all the possible values of each field, but this would quickly become unwieldy as the number of fields increases. Instead, you might decide to keep track of only the most important ones. For instance, you might decide that the title is the most important part of the URL, so you'd just store the title there. Then, when someone asks for the full URL, you'd look up the title in your database and then fetch the rest of the URL from wherever it lives.

The second step is to figure out how to represent the data. If you're storing the title in a single field, you'll need some way to differentiate between different titles. One approach is to use a hash function to generate a unique identifier for each title. The result will be a string of numbers and letters. So, instead of having a list of titles, you now have a list of strings of numbers and letters.

Now comes the tricky part. As I said before, you don't actually want to store the entire URL. You only want to store enough information to find the original URL.

Some websites create short links to make sharing links via instant messaging easier, and to make it cheaper to send them via SMS . This can be done online, at the web pages of a URL shortening service; to do it in batch or on demand may require the use of an API.

A few well-known websites have set up their own URL shortening services for their own use – for example, Twitter with t.co, Google with g.co, and GoDaddy with

In URL shortening, every long URL is associated with a unique key , which is the part after its top-level domain name . For example, https://tinyurl.com/m3q2xt has a key of m3q2xt. Not all redirection is treated equally; the redirection instruction sent to a browser can contain in its header 

There are several techniques to implement a URL shortening. Keys can be generated in base 36 , assuming 26 letters and 10 numbers. In this case, each character in the sequence will be 0, 1, 2, ..., 9, a, b, c, ..., y, z. Alternatively, if uppercase and lowercase letters are differentiated, then each character can represent a single digit within a number of base 62 (26 + 26 + 10). In order to form the key, a hash function can be made, or a random number generated so that key sequence is not predictable. Or users may propose their own custom keys. For example,

and javascript: URLs are not supported for security reasons (to combat attacks like cross-site scripting session hijacking ). Some URL shortening services support the forwarding of mailto URLs, as an alternative to address munging , to avoid unwanted harvest by web crawlers bots . This may sometimes be done using short, CAPTCHA -protected URLs, but this is not common. 

Makers of URL shorteners usually register domain names with less popular or esoteric Top-level domains in order to achieve a short URL and a catchy name, often using domain hacks . This results in registration of different URL shorteners with a myriad of different countries, leaving no relation between the country where the domain has been registered and the URL shortener itself or the shortened links.

Top-level domains of countries such as Libya .ly Samoa .ws Mongolia .mn Malaysia .my Liechtenstein .li ) have been used as well as many others. In some cases, the political or cultural aspects of the country in charge of the top-level domain may become an issue for users and owners, but this is not usually the case.