I use short links for everything, my blog posts and my GitHub repos and my booking page, because long URLs look ugly in messages and emails and are hard to share verbally. Bitly used to be free for custom domains and then they started charging and then they raised prices again, so I switched to Shlink which is a self-hosted URL shortener with analytics and tags and an API, all on my server and all free.
Shlink runs two containers, the main server and a web client interface. You set environment variables for your default domain and HTTPS settings, run docker compose up, and the web client connects to the server through an API key that you generate through the command line. The setup takes about five minutes.
services:
shlink:
image: shlinkio/shlink:latest
restart: unless-stopped
ports:
- "8080:8080"
environment:
DEFAULT_DOMAIN: go.yourdomain.com
IS_HTTPS_ENABLED: "true"
volumes:
- data:/data
shlink-web-client:
image: shlinkio/shlink-web-client:latest
restart: unless-stopped
ports:
- "8081:8080"
environment:
SHLINK_API_URL: https://go.yourdomain.com
depends_on:
- shlink
volumes:
data:
The server handles the actual short URL redirects and analytics while the web client is the management UI you use to create and inspect links. The web client talks to the server through its REST API, which is why SHLINK_API_URL has to point at your server’s public URL, not the internal container address. The depends_on line makes sure the server starts before the client, although the client will retry on its own if the server is not ready yet.
Creating short URLs is straightforward through the web interface. You enter the long URL and optionally a custom short code and some tags, and Shlink generates a short URL on your domain. Custom short codes are easier to remember and share than randomly generated strings, so I use blog-post or git-repo instead of something like a three b f two.
The analytics are the feature that makes this useful beyond just link shortening. Shlink tracks total visits and unique visitors and referrers and browsers and operating systems and even geographic location. Clicking on any short URL shows its full analytics so you can see which channels drive the most traffic.
The REST API lets you create short URLs programmatically from your other tools. I use this in n8n to automatically create short URLs when I publish a new blog post, so every new article gets a clean short link without any manual work. The command-line tool works through Docker exec for scripting and automation.
Bitly is a great product but paying forty dollars a month for short links when Shlink exists and does everything Bitly does on your own server does not make sense. Set it up once and you own your links forever.
If you have thoughts on this do email me or subscribe to the newsletter for more self-hosting recommendations.