How to Create Your Own Custom URL Shortener (for Free!)

An URL shortener is really awesome for online businesses if you want to share content online.

But regular URL shorteners have some problems, and can come with monthly fees.

So in this guide, I’ll show you how you can create your own custom URL shortener for free in less than an hour πŸ™‚

The only thing you need is hosting and a short domain.

Here’s what we’ll cover:

Let’s dive in! πŸš€

Part 1

About URL Shorteners

Before we’re creating one.

Let’s first talk about what it is.

And why it’s so handy for your online business.

What is a URL shortener?

A URL shortener is a service that takes a long URL and turns it into a shorter URL.

Example: www.maxvancollenburg.com/really-long-url/ β†’ maxvan.co/a8s

The URL shortener “remembers” the full address of the URL you give it and when other users go to the shortened URL, they are automatically redirected to the full address.

This is useful because shorter URLs are easier to remember and share.

URL shorteners also track how many people click on the shortened URL, which can be useful information for your online business πŸ€“

What to use a URL shortener for?

You can use shortened URL’s for plenty of handy things;

  • Use shortened URL in a tweet
  • Use shortened URL in a YouTube video
  • Use shortened URL in a Facebook post
  • Use shortened URL in an email
  • Use shortened URL in a text message
  • Use shortened URL in a (guest) blog post
  • Use shortened URL in a forum post
  • Use shortened URL in a chat message
  • Use shortened URL in printed advertising

I’m personally using it most on my YouTube Channel, and when answering questions in Facebook Groups.

The problem with free URL shorteners

There are plenty of URL shortening services that let you shorten URLs for free.

But the biggest problem is that those free services use their own domain, which often have a bad reputation because scammers & spammers use them to hide the destination of that link.

So the solution would be to use your own custom domain with these services.

And while that’s possible with most URL shorten services, they almost always ask a premium for it.

Why create your own custom URL shortener?

Creating your own custom URL shortener has a couple of benefits;

  • Use your own domain name.
  • Privacy-friendly since only you can access the data.
  • Cheaper because you only pay for hosting & domain.
  • No limits: create & track as many links as your heart desires.
  • More control as you can do whatever you want.

But there’s maybe also some downsides to consider;

  • You have to install the application yourself.
  • It’s smart to update the application sometimes.

For me it was a no-brainer, and I actually enjoyed setting it up πŸ’

Part 2

Create your own URL Shortener

You don’t have to be a programmer.

The hardest part is to come up with a good domain name.

Let’s go!

For our custom URL shortener, we’re going to YOURLS.

(YOURLS stands for Your Own URL Shortener)

I’ve been using YOURLS for the last 5 years and created 179 shortened links that have been clicked 51.900 times so far:

how much i used yourls

I love YOURLS for a couple of reasons:

  • It’s completely free: no monthly fees or licenses πŸ₯³
  • It’s easy to use: no reason to make url shortening complex (which many online tools do justify the price).
  • Low maintenance: I only had to update it once in the last 5 years.
  • Detailed statistics: you can see traffic statistics for each short URL.
  • It has an API: bit techy, but allows you to create short URLs in other applications.

This is what the dashboard looks like:

yourls dashboard

Personally, I think it looks a bit outdated, but I’m too lazy to customize something only I see πŸ€·β€β™‚οΈ

What’s also nice, is that you can see detailed statistics of each short URL:

yourls statistics of short url

Let’s build it, shall we? πŸ’ͺ

Step #1: choose your short domain

You could use your main domain, but it’s probably smart to come up with something shorter.

For example, the URL of this website is maxvancollenburg.com and I’m using maxvan.co as my URL shortener.

But you can also get a bit more creative than me πŸ’

Here are some tips:

  • Make it easy to remember: handy if you print it or if people have to type it over from a video.
  • Look if you can shorten your existing domain name somehow.
  • Use a related word to your business.
  • Be creative with domain extensions: you don’t have to use .com necessarily.
  • Avoid something completely random like j43hf.com since it will look spammy.
  • Avoid dashes. They don’t look nice and it’s more likely for people to make typo’s.

Go crazy! πŸš€

Step #2: register your domain

I recommend registering with Cloudflare as they register domains with no price markupβ€”you pay what they pay for registration.

Besides being cheap, they are one of the fastest DNS providers in the world, which means people get connected to your domain a few milliseconds faster compared to most other providers.

To register a new domain, create an account & go to Register Domains:

steps to register domain in cloudflare

If it’s available, you’ll see a Purchase button πŸ™‚

It’s also okay to register your domain elsewhere if you’ve already registered your domains somewhere else. It doesn’t matter so much.

Step #3: get hosting

You can use any hosting you like because it’s such a lightweight application. It takes up 5 MB storage, and just one database to store shortened URLs in.

I’m using Cloudways because I already have a server there for my website, so it doesn’t cost me anything extra to add an extra website.

Step #4: create database

To store the shortened URLs that you create, and to track how often links have been clicked, we’re going to need a database.

Creating those is usually pretty easy, but it depends on which hosting provider you’re using.

Step #5: download YOURLS

Download the YOURLS source code by going over to Github to grab the latest release.

download latest yourls release on github page

Step #6: modify config file

In the User folder, rename the file config-sample.php to config.php.

Then, open the file in a plain text editor and find the code below πŸ‘‡

/** MySQL database username */
define( 'YOURLS_DB_USER', 'your db user name' );

/** MySQL database password */
define( 'YOURLS_DB_PASS', 'your db password' );

In that file, replace what I marked in red with your database username and database password.

After you’ve done that. Hit save πŸ˜„πŸ’Ύ

Step #7: upload files

Now it’s time to upload all the YOURLS files.

You can do this through the file manager of your host, or use a FTP manager like Transmit (what I’m using) or FileZilla.

Step #8: finish installation

Go to https://yourshortdomain.com/admin/ and follow the steps to complete the installation πŸ™‚

When setting your username & password, use something incredibly strong so it doesn’t get hacked.

Optional: redirect homepage

Since your URL shortener is probably not for public use, you don’t have any use for the homepage.

That’s why I recommend to upload a simple file to redirect the homepage of the URL shortener to the homepage of your main website.

Create a new file called index.php and add the code below to it.

<?php
header("Location: https://www.yourwebsite.com");
die();
?>

(don’t forget to replace the domain)

Then, upload it to the main folder where you also uploaded the other YOURLS files.

The homepage should redirect now to your website πŸ˜„

That’s it!

Your URL shortener is now ready to use πŸ€“

The end

Now it’s your turn

comment illustration

I hope you enjoyed this guide about URL shorteners.

Now I would like to hear from you:

Did this guide help you to create your own custom URL shortener?

Or do you think it’s too much effort?

Whatever it is, let me know in the comments below.

Avatar of Max van Collenburg
Max van Collenburg

I'm addicted to travel, love a good cappuccino, have two cute cats, and craft actionable content for online business owners that want to grow their business with non-sleazy marketing & automation. More weird facts about me here.

17 thoughts on “How to Create Your Own Custom URL Shortener (for Free!)”

  1. Hey Max,

    Thanks for sharing this amazing tip!

    Wanted to check, if you are aware of any such QR code generator tool as well which can help us create QR code and to track them!

    Cheers,
    Richa

    Reply
  2. I couldn’t get this to work as described as I lack the technical know how. But I was determined to find a way and eventually I managed to install it on a cheap shared hosting account I set up just for the purpose using one of the apps in the c panel. Thank you for the inspiration! I’ve wanted a branded URL shortener for ages but taking on yet another software subscription put me off.

    Reply
    • Hey Sarah! Happy to hear you got it to work! πŸ’ͺ

      Is there anything I could’ve done differently in this guide to make it easier?

      Reply
      • I tried it the way you described and got really stuck with accessing the SQL database I’d created because I was on a shared hosting service and my host told me I had to create some sort of tunnel πŸ€·πŸ»β€β™€οΈπŸ˜¬ I did attempt to follow their instructions but it was beyond me.

        Anyway after a bit more digging I found that if your host offers c panel you can install YOURLS using Softaculous. It’s really easy. Like super easy. And got the job done in under 10 minutes.

        Reply
        • Yes, databases can be a bit tricky because it’s different at every host.

          But glad you found a way to install it with Softaculous! Maybe others that read this who use cpanel can check if that’s a possibility for them too πŸ˜„

          Reply
  3. πŸ™πŸΎ Thank you so much, Max, for your incredible help! πŸ™ŒπŸΎ Here are a few more tips for beginners that might be helpful:

    βœ… Make sure to define your database name under where you’ve input the password. This will ensure that your links are properly stored and organized.
    🚨 Don’t forget to define YOURLS_SITE with your short link – if you skip this step, you won’t be able to run the installer! 🚨
    πŸ’‘ For added security, go ahead and replace the very basic and unsafe username and password defined under yourls_user_passwords. This will help protect your links from unauthorized access.

    πŸ™πŸΎ Thanks again for the fantastic tutorial, Max! πŸ™ŒπŸΎ

    Reply
  4. Hi Max, thanks for the step by step guide to set up YOURLS successfully!

    I have a primary site: https://NuevaZelandaTours.com.
    https://NuevaZelandaTours.com/en/ (English site)
    https://NuevaZelandaTours.com/es/ (Spanish site)
    https://NuevaZelandaTours.com/ca/ (Catalan site)

    My Catalan webpages can be shortened with my own Catalan domain: NovaZeland.cat on YOURLS πŸ™‚

    Re: Redirect the homepage of the URL shortener to the homepage of your main website

    My goal is to redirect homepage of https://NovaZelanda.cat to the Catalan main site https://nuevazelandatours.com/ca/.

    Attempt#1: Following your suggestion, I added the code as below to a new NotePad, and saved it as index.php into User folder of YOULRS.1.9.1 file.

    Attempt #2. I copied and pasted the code “header(“Location: https://nuevazelandatours.com/ca/“);
    die(); ” into Config.php file under User folder of YOURLS.1.9.1.

    Attempt #3: I also used Redirection plugin to redirect https://NovaZelanda.cat to https://NuevaZelandaTours.com/ca/, URL only, but it automatically redirect to URL & server.

    https://NovaZelanda.cat is now redirected to https://NovaZelanda.cat/admin (YOURLS), instead of my targeted URL https://NuevaZelandaTours.com/ca/.

    Could you kindly advise how to fix it?

    Reply
  5. Hey max I am using hostinger’s web hosting but the problem is when I create a new website and do all the steps above. When I type mydomain.com/admin it opens a WordPress admin panel and not the yourl panel!! What should I do?

    Reply
    • Hey Ujjwal! I don’t have experience with Hostinger, but it sounds like there’s maybe an active WordPress installation on the same domain name? For the URL shorter I would recommend to choose a new domain. Hope that helps! πŸ’ͺ

      Reply

Leave a Comment