How-to create personal URL shortener in 5 simple steps

published in category technology on May 27, 2016

By following these 5 simple steps, you can run your own url shortener in Azure

Url shorteners become handly when you want to share long and complex links to your audience. Having the links shortened makes them more memorable and easier to use for example in presentations. There are plenty of options available and some of them allows you to use your own domain too. I have been using a free software called YOURLS for some time now and it has worked just fine. However, YOURLS requires a database and to my needs it just seemed to heavy. So I started to think if there was a simpler way to achieve the functionality that I need. As it turned out, with just these 5 simple steps, I was able to create my own url shortener running in Azure. And the solution contains just one simple file!

1. Create GIT repository

I use BitBucket for my private repositories and creating a new repo is just a matter of clicking a button in their web UI. No magic in this step.

2. Add web.config to your repository

The only file you need in your repository root is simple web.config file describing the redirects that you want to use for url shortening. So create a file called web.config and commit it to your new repository. For each link a location block needs to be added to the config telling the shortened url and the actual link:

In this example the shortened link would be something like http://my_short_domain/photos and it would take the user to my photos site. Modifying the web.config can be done using BitBucket’s web UI so for adding new urls you only need access to a web browser.

3. Create Azure web app and enable continuous integration

Creating new web app in Azure portal is yet again just a matter of couple mouse clicks. The hardest part is to come up with the name for your app (don’t worry it really doesn’t matter that much in the end):

Once you have your application up and running it is time to connect your git repository to the application. Use these instructions.

Your url shortener should now be working, but the urls are not that short yet as the web app is running under the default domain.

4. Register a domain

Now comes the hardest part of the whole process: finding free domain that suits your needs. I wanted to have a domain that could somehow be connected to my name. I’ve been searching for a good domain for quite some time and in the end I found one that I liked from American Samoa. My new url shortening domain is

I don’t go into the details of the domain registration as it varies quite a bit depending on the provider you choose. Just make sure that you choose a provider that gives you access to modify the DNS records. You need that ability in the next step.

5. Set up DNS for your domain

To be able to route requests pointed to your own domain to the Azure app, you need to modify the DNS records of your domain. As part of this process you also need to add some special records so that Microsoft can vcerify that you actually have control of the domain. There are very good instructions for this step and it is more just about waiting the for the chages to propagate.

That’s it!

There are couple of downsides that I can think of about this approch that I think needs to be mentioned:

The syntax of your web.config needs to be correct. If you mess up the with one link, you might end up breaking all the links. So just be carefull. You also need to handle encoding the urls manually.

You don’t get any statistics automatically. Some of the tools gather analytics information of the clicks your links get. With this simple solution you only get the redirecting functionality and therefore is not for everybody.

Now go and add some more shortening configurations to your config and see how Azure deploys the changes automatically.

My name is Juha Ryhänen. I’m interested in everything related to productivity, remote work, automation and cool gadgets. This is my personal website where I write about the things I find interesting. Maybe you do too? [More]

+358 50 543 4543 | [email protected] | Twitter