Last night I set up my new domain http://dntd.cc (it’s not very exciting if you visit it) to handle all my own URL redirections from now on. I’d been meaning to do this and in light of Tr.im’s imminent demise I thought it was prudent to go ahead and do it now. This is not (and will not become) a public service, it’s purely for my own use.
After looking around at some options, I settled on using YOURLS to power dntd.cc, for a couple of reasons:
- It’s lightweight and pretty simple
- It’s written by 2 people I know of, and respect, who are prominent members of the WordPress community
- It comes with a companion plugin that allows me to automatically create short URLs for all of my WordPress Posts and Pages
- I can also add arbitrary shortlinks using a very simple admin interface if I want to link to something else.
With all those benefits in mind, here’s what I had to do to get it running:
- Register and set up dntd.cc, confirm that it was resolving and that I had access to that directory (long story, but this was more complicated than it should have been
)
- Copy all the YOURLS files into that directory
- Create a new database to hold things
- Set up the config file at /includes/config.php with your database details
- Run the install script at /admin/install.php which gets YOURLS set up and installed
- At this point you’d think you were ready to go, but I realized that I really needed to set up some Apache Rewrites and stuff to really have my site running. I removed these files:
- public-sample.php
- readme.html
- test-api.php
- Then I dropped in this .htaccess file to handle redirecting shortlinks to where they need to go:
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ([0-9a-zA-Z]+) yourls-go.php?id=$1 Options -Indexes
- Then I went ahead and grabbed the WordPress plugin for YOURLS and installed that, and configured it just to do these things:
- My own install,
- Local, on the same webserver (and entered the path to my config file)
- Skipped my Twitter login details and then set it to generate a short URL on Post and Page publish
Now, whenever I publish a new Post or Page, there’s a new box on the right of my edit screen that tells me my shiny new short URL. If I want to create my own shortlink for anything non-WordPress, I just log into the YOURLS admin interface and I can do so very quickly.