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

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,, 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 or

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.

YOURLS source files
YOURLS source files uploaded to site

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.

YOURLS config file
YOURLS config file located in the user folder

Open config.php and add the MySQL credentials, site options, and user access details. Save the file and then navigate to 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/.

YOURLS plugin folder
YOURLS plugins

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

YOURLS plugin management
YOURLS plugin manager

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.

YOURLS UTMs for links
Enter campaign variables to create UTM parameters in YOURLS shortened links

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.

YOURLS random plugin
Setting the length for random shortened URLs in YOURLS

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

Random shortened link
Shortened link using YOURLS random shortcuts plugin

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.

YOURLS bookmarklets
Bookmarklet options in YOURLS

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.

YOURLS settings
YOURLS settings page in WordPress

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 visitor’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.

SQL queries in phpMyAdmin on Pair

Supporting YOURLS development

If you use and enjoy YOURLS, I encourage you to support its development via Open Collective.

Related Articles

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 @[email protected]