Open/close side menu
C.C. Hogan

Creating my own short URLs

Comment on this article

Oh, this was a bit easy...

URL shortening is what things like Bitly offer - basically taking your great big url and making a little one that redirects people to the big one.  it is very useful and I have used bitly myself, but I rather fancied having my own system using my own domain name, so that it was obviously still part of my brand, as it were.

Using URL shortening has proved very useful. For instance, I moved a couple of books on Kobo recently which meant they had new URLs. Since I always use URL shortening, I could just change which URL the short version pointed at, and I didn't need to change all my ads.

I really thought this was going to be a lot more complicated than it was. I had in mind possible server configurations, messing with htaccess and all sorts of strange ideas.

A quick search on Google brought me to a rapid halt with a simple solution:

YOURLS by @ozh

This relatively simple PHP script is a free, open source utility that allows you to create a url shortening service on your own server.  It can be run as a public service or, as I have done, a private service for one little, hairy, mostly sober writer.

Step 1 - buy a domain.

As a standalone, you need to have this utility on a domain all of its own as otherwise, you will end up in a complete mess. So I was not going to be able to use it on cchogan,com or aworldcalleddirt.com.  I needed a new one.

Running off to your favourite domain supplier, find something that makes sense. I chose ccho.mobi.  Ideally, I could have gone shorter, but the mobi ending rather appealed to me considering my books are on Kindle!

Step 2 - A bit of hosting.

You now need a host.  The script works perfectly fine on a shared system and unless you are setting up some great big public facility, that is all you need. I already have a shared server with Kualo  (a very good company), so I set mine up on there, but get anything cheap. Basically, something apache-ish with MySQL database - a handful of dollars a month job.  Check the requirements on the YOURLS website, but it is run of the mill. If it will run a CMS like Processwire, then it will run it.

Step 3 - Create a database

On your new website control panel, create a new database and database user. Call it anything! Normal rules - nice hard password, please. Use their generator that comes with the control panel, if it has one.

Step 3 - Upload it and a little edit.

Go and grab the latest release from their Github account, unzip the archive, and upload the files into the root of your website.  Not a sub-folder, just straight into the root, which is normally a folder called public_html, or similar.  You know you have done it right, because you should have a long list of files in there and a folder called user.

Open the user folder and rename the config sample file to config. php.

Edit the file and follow the instructions.  The first bit is the database settings. So, name of database, database user, password and hostname.  The hostname needs to include the port, so it is most likely to be localhost:3306.

Under Site Options, put the url of your site (mine is http://ccho.mobi) and work your way down the list.  Most of these you can leave alone.

When you get to YOURLS_COOKIEKEY, put something ridiculous in there like alkjdn3kndolkqlkdjas.  You wont have to remember it, but once it is set, never change it or everything will break!

The last bit you must do is set up a username and password under $yourls_user_passwords.  Nice, difficult password please! You can set up several, but you probably only need one. The example has two, so remove one!

It should look like:

$yourls_user_passwords = array(
    'myname' => '89d0jjo9owd9j3klj',
    );

Step 4 - Install.

Now go to your browser and go to yourdomain.com/admin/

Click install.

And you have done it.  log in and set up some URLs.  It is really, really easy to use!

There are also loads of plugins available, most of which are no use to you probably. One useful on is a CSV importer if you are creating long lists, for instance, if you have loads of books being sold everywhere like me! Plugins are here.

Of course, since you are the only one using it, you have total freedom and wont have a problem with someone else using the good urls.

So, there you go and to prove it works, here is my url for my brilliant book Dirt on Smashwords:  http://ccho.mobi/dirt-sm - go on, click it. The book is FREE!

Full (and better) instructions are available on the YOURLS website.

 

Go for it!

 

Comments

Please feel free to comment - no anger, no bad vibes, no trashing people. Just sit around, enjoy a flagon of beer and mull over the world. You can login with Disqus, Facebook, Twitter or Google.

Series One & Two are out now!

Start series one with Dirt for Free, and start reading the brand new series two with Girls of Dirt for only 99p!

Girls of Dirt includes a recap of series one.

Get it now at the Dirt website

The Stink Is Here

North London, 1976. The longest, hottest summer on record. The water is running out and the kids hate their parents. Which bunch of idiots would think it is a good idea to start a band?

The Stink

Visit The Stink Website