How to create a free URL shortener like Bitly and TinyURL with your own domain
You don't need a commercial service or significant resources to shorten URLs. Learn how to self-host a URL shortener with open-source software and a custom domain on a cheap shared hosting plan.
URL shorteners like TinyURL were first introduced to keep long and unwieldy links from breaking in email messages. They became even more popular when social networks like Twitter launched because long links used too many characters in posts. URL shorteners, such as Bitly, were seen as essential tools when sharing links on social media.
Eventually, social networking platforms like Twitter updated how they handled links. They visually truncated long URLs, and they set a limit for the number of characters that counted towards the maximum characters allowed per post. These changes eliminated the primary need for URL shorteners on social posts, but marketers continue to use them for other reasons.
Why marketers use URL shorteners
- Campaign Tracking – Marketers add campaign variables to the original URL and then shorten it. That enables them to track the success of a campaign in site analytics services like Fathom and GA.
- Offline Campaigns – Similar to using a service like CallAction or CallRail, multiple shortened URLs can be created for the same link. Coupled with campaign variables, marketers can better understand which channels perform best.
- Custom Domains – Marketers like to use abbreviated short domains (i.e., custom domain) to brand short URLs. Most popular URL shortening companies charge a fee to use a custom domain.
- Vanity URLs – Marketers prefer naming short URLs with words associated with the campaign. Most desirable naming options are taken when using the domain of a shortening service bitly.com or tinyurl.com. Which is why the use of a custom domain is preferred.
- Affiliate Marketing – Some affiliate links use strange-looking domains and long URLs with strings and special characters. Shortening an affiliate link, especially with a branded custom domain, can make the link look less suspicious.
How to setup and host your own URL shortener
The first step to setting up a URL shortener is to download YOURLS. YOURLS, which stands for “Your Own URL Shortener,” is the best open-source URL shortener I’ve used. And it has the same essential features as Bitly and TinyURL.
The next step is to make sure you have a hosting provider that supports PHP and MySQL. I recommend using a shared hosting account with Pair. I’ve used them for over two decades, and they are affordable, performant, and highly reliable. If you go with Pair, use this referral code to get 20% off a new account: pairref-QQGBi69J.
Choosing a custom domain
YOURLS can use whatever domain you want. I use clck.io
, coywolf.io
, and an emoji domain (🐺💡.to
) for my URL shorteners. If you can’t find a good short domain to use, consider using a subdomain from an existing domain. For example, you could use go.yourdomain.com
or share.yourdomain.com
.
Once you choose a domain, add it to your shared hosting account. I also recommend using Cloudflare to take advantage of its free SSL, DDoS protection, performance boosts, and access to smart page rules for your domain.
Setting up YOURLS
Create a new MySQL database with your hosting provider and save the account credentials for later. Then, upload YOURLS to your site folder using an FTP/SFTP app like Transmit.

Setting up YOURLS is similar to configuring the wp-config.php file for WordPress. Open the user
folder and then either rename or copy and rename the config-sample.php
file to config.php
.

Open config.php
and add the MySQL credentials, site options, and user access details. Save the file and then navigate to yourdomain.com/admin
to complete the setup.
YOURLS Plugins
To get the most out of YOURLS, you’ll want to add some useful plugins. After you download the plugins, upload them to /user/plugins/
.

Then go to the YOURLS admin page and click on the Manage Plugins link to activate them.

Campaign variables plugin
YOURLS requires a plugin to track campaigns. Download and install Google Analytics for YOURLS to add the option to include campaign variables with shortened links. Even though Google Analytics is in the name, GA isn’t required. The plugin stitches campaign parameters into a UTM string compatible with most site analytics services, such as Fathom Analytics.

Bitly-like random keyword plugin
YOURLS now comes bundled with a Bitly-like random keyword plugin. When you activate the plugin, you can choose a random keyword length.

If the length is set to 5, all new links without a custom name will use a random keyword, similar to how Bitly works.

YOURLS Bookmarklets
The Tools page in the Admin contains bookmarklets that can be added to the browser’s toolbar or bookmarks. The bookmarklets make it possible to quickly create a random or custom keyword short URL for the page you’re visiting. There are also bookmarklets for shortening and sharing with social networks.

Using YOURLS with WordPress
YOURLS has an API, making it possible to shorten URLs with third-party solutions. There are several plugins, integrations, and apps to choose from. I use the YOURLS Link Creator for WordPress to shorten URLs for new posts.
After installing and activating the plugin on WordPress, copy the API key (aka “secret signature token”) from the Tools page in the YOURLS Admin. Then paste it into the API Signature Key input field. You will also need to enter the custom domain you’re using. All of the other options are optional.

When you edit a published post or page, there will be a new option to create a short URL. If you selected Auto generate links in the settings, the shortened URL would be created automatically when the page is first published.
Anonymizing traffic data for privacy laws
If you’re concerned about privacy laws – especially European privacy laws where Austria and France recently declared Google Analytics illegal – you will want to install and activate the YOURLS Anonymize Log plugin. The plugin keeps YOURLS from saving the MySQL database’s IP address and browser user agent.
If you’ve already set YOURLS up and collected data, you can remove the entries using this SQL code in phpMyAdmin.

Supporting YOURLS development
If you use and enjoy YOURLS, I encourage you to support its development via Open Collective.
Jon is the founder of Coywolf and the EIC and the primary author reporting for Coywolf News. He is an industry veteran with over 25 years of digital marketing and internet technologies experience. Follow @henshaw