Using Google URL Shortener with Your Domain! For Free!!

time to read 4 min | 845 words

I sometimes feel like URL shorteners are some of the most understated tools in internet marketing, and there have been more than a few times that I wished I’d had someone share some advice on URL shorteners.

For instance: What do you do with really long links? What if you want to track the results? What if the link—long and unwieldy—upstages the content? What if I am on a platform where every character count? (on Twitter for instance)

What URL Shorteners Do (And Don’t Do)

URL shorteners were originally created to address stubborn email systems that wrapped an email after 80 characters and broke any long URLs that might have been in the message. Once Twitter (and other social media) took off and introduced the 140-character limit, that shortened link became even more important.

It wasn’t long before link shorteners quickly became more than mere URL shorteners.

They began to allow publishers to track the links they posted with analytics. They keep URLs that are loaded with UTM tracking tags from looking ugly by hiding the length and characters in the UTM tracking system.

Sounds great, right? Who wouldn’t use this system?

Use A Custom Domain With URL Shorteners

With services like Domainr and IWantMyName, you can easily get a custom domain to use with link shorteners.

Why would you want to do this?

Using a custom domain with your link shortening service is a way to confront the spam and distrust issue.

Your links become branded as yours. Your brand, your name–it’s carried across into the very links that you are sharing. This helps let people know they aren’t spam. As long as your custom domain relates to your brand and you use it consistently, people will know that the links you are sharing have been vetted by you.

Also, a custom domain might improve the amount of clicks your link receives. According to RadiumOne, URL shorteners that offer vanity domains can increase sharing up to 25 percent.

What do I need?

This is the best part, you only need a couple of things which in this day and age you have probably already got access to.

  • A domain name, I’m going to be using go.rezhajulio.id . This domain should not be used for anything else.
  • Hosting space for the domain, this can be Apache or Nginx driven I’ll provide examples for both, you just need to be able to make a change to the vhost configuration. For Apache we can do this easily via the .htaccess file. Nginx people will probably be running a VPS or similar so I’ll assume you have access to create a new vhost configuration.
  • A Google account, if you want to have the URLs you generate with goo.gl be unique to your account and kept in your dashboard to track number of clicks etc. Otherwise anonymous access will work just fine to generate the URL.

I’m ready to go, what’s next?

Everything ready to go we can make the magic happen!

Apache configuration

Apache people create a .htaccess file in the root web directory and add the following lines to it. Of course if you have access to the main vhost configuration then use that to save Apache a little bit of leg work reading in the .htaccess file.

RewriteEngine On
RewriteRule ^(.*)$ http://goo.gl/$1 [L,R=301]

The code above is very simple. This rewrite rule simply takes the requested URL and swaps out your domain for the goo.gl domain and marks it as a permanent (301) redirect.

Nginx Configuration

Nginx people you need to create a server block, I’ve always followed the sites-available, sites-enabled pattern used by Nginx on Ubuntu as I find this to be the most organised method but do it however you’ve been working so long as Nginx can read this server block it will answer any calls to the domain.

server {
  server_name go.rezhajulio.id;
  rewrite ^ http://goo.gl$request_uri permanent;
}

The server block does the same as the Apache rule above and it redirects any requests onto goo.gl. Simple.

How do I use this to make my own short urls?

By now you’ve probably figured it out but just in case. Visit goo.gl and sign in if you want to keep statistics on your links otherwise you will just see the input box Paste your long URL here: follow the instructions and paste in your long URL and shorten that URL!

In return you’ll get a short URL in the form of http://goo.gl/ELenCw all we are interested in is the bit after the domain. We can then append that to our custom domain https://go.rezhajulio.id/ELenCw like so and you’re done!

Now when you use that URL it will first take a trip to your server where it will find the rewrite rules we setup, these will then send the request onto goo.gl to be translated into the long URL and the correct page.

Seriously is that it!?

Yup, that’s it. This method ensures you can still use the analytical data collected by the goo.gl service in their pretty graphs and you get to use your own domain.