Blog

How a URL shortener actually works

How a URL shortener actually works
Jorge Lapa
Jorge Lapa
Founder · · 4 min read

Short links look like a trick and are closer to plumbing. Someone clicks go.acme.com/pricing, their browser goes somewhere else entirely, and the whole thing is over before the destination page starts to paint.

The lookup

The short domain is a real domain with real DNS records, pointing at the shortener's servers. When someone clicks, their browser resolves go.acme.com and sends a normal HTTP request for /pricing.

Two things in that request identify the link: the hostname and the path. Both matter. The same path on two different domains is two entirely different links, which is why a dozen brands can each run their own /pricing without ever colliding.

If nothing is registered at that address, the server answers 404. If something was registered and has since been deleted, a good shortener answers 410 Gone rather than 404, which tells crawlers the address is intentionally dead and stops the path being quietly reassigned to someone else's link later.

The redirect

When the lookup succeeds, the server does not fetch the destination or proxy it. It answers with a redirect: a status code, and a Location header naming the real URL. The browser follows. From there the visitor is on the destination site and the shortener is out of the picture.

The status code in that response matters more than it looks:

Status Meaning Effect
301 Moved permanently Browsers cache it, sometimes indefinitely
302 Found Temporary, checked again next time
307 Temporary redirect Like 302, preserves the request method

A 301 is tempting because it sounds authoritative and passes link equity to the destination. It is usually the wrong answer for a short link. Browsers are entitled to cache a 301 and stop asking, so a visitor who clicked your link last month may never reach your server again. Change the destination and those people keep landing on the old page, with no way for you to reach them and nothing in your analytics to tell you it is happening.

GoGoLink answers with a 302 for this reason. The redirect stays editable, and every click keeps arriving at a server that can send it somewhere new.

Where the click gets counted

Because the visitor passes through the server on the way, the click can be recorded there. Nothing needs to run in the browser, which means no tracking script on the destination page and nothing that depends on the visitor's consent settings or ad blocker.

The request itself carries most of what a click report is built from. The Referer header names the site the visitor came from, and the User-Agent gives away their browser and operating system. The IP address does two jobs: it resolves to a rough location, and it feeds a hash that counts unique visitors. The address itself is never written down. The salt behind that hash rotates every day, so yesterday's visitors cannot be matched against today's. What comes out the other side is clicks by country, region, city, device, browser, and referrer, with no cookie set and no profile kept about anyone.

Query parameters ride along

A short link can carry query parameters of its own, and a well-behaved shortener passes them through to the destination rather than dropping them on the floor. So go.acme.com/pricing?plan=team arrives at the destination with ?plan=team still attached.

The link's own UTM parameters get added here too. They are appended to the destination at redirect time rather than stored inside it, which is the detail that lets you fix a misspelled campaign tag after the link has been printed on a banner. Collisions go to the owner. Where a forwarded parameter and one set on the link share a name, the link owner's value is the one that lands.

Why the domain is the part worth owning

Everything above works the same regardless of which domain sits at the front. What changes is what happens when the shortener does.

A link on a shared shortener domain is only as durable as the company running it. When one shuts down, every address ever created on it dies the same afternoon, and there is no migration path because you never controlled the hostname in the first place.

go.acme.com is different. The CNAME record behind it lives in your own DNS, and you can repoint it at another provider in an afternoon without a single published link changing. That portability is why we put branded domains on every plan instead of behind an upgrade.

← Back to blog