How does a URL shortener work?

A shortener can turn a long URL into a much shorter URL. What magic is this?

A pair of scissors cutting the word

If you used the Internet, you also used a URL shortener, even if you weren’t aware of it. URL shorteners provide a convenient way to share web addresses. But do you know how they work?

URL shortening has two main parts. The first is to take an original URL and generate a shorter one. The second is the reverse process: transforming a short URL into an original URL.

How generating a shorter URL works

A URL shortener takes a URL and generates a shorter one, around 10 characters. The shorter URL is unique and automatically redirects users to the full address of the original URL. But how does the generator do this?

To generate a short URL, you start by entering a URL on the shortener’s webpage. This URL is sent to the server, which validates it and checks for code injections and invalid parameters.

Related: Ways to Quickly Shorten URLs Right from Your Browser

At this point, the server stores the longest URL in a database. It then generates a unique hash code and returns it as a short URL. Hashing is a process that maps data of any size to a fixed size output. This allows a shortener to guarantee the longest length of its short URLs.

What happens when you click on a short URL?

The short URL acts as a key that matches the original URL. When you try to open a short URL, your browser sends an HTTP request to the shortening server.


An illustration of a hand pointing at abstract text on a computer screen surrounded by icons

The service looks for this short URL in its database. If the resource exists, the web server retrieves the longer original URL and redirects to it. If it doesn’t recognize the short URL, the server will redirect to an error page usually a 404.

Related: You can now shorten form URLs in Microsoft Forms

Using a shorter URL is better

Long URLs take up a lot of characters. So sharing them in resumes, emails, and microblogging sites like Twitter can be inconvenient. Shortening a long URL makes it easier to share the link. Advertisers often use short URLs in printed materials.

However, that’s not all! URL shorteners often provide additional features like usage tracking so you can see how your link is performing.

Shortened URL
3 Ways to Quickly Shorten URLs Right from Your Browser

In a world of microblogging and mega long links, URL shortening can be incredibly useful. These tools will allow you to shorten URLs quickly and easily.

Read more

About the Author

Comments are closed.