Skip to Main Content

Make Your Own URL Shortening Service


URL shortening services are ubiquitous on Twitter and other cramped online spaces. They won't all last, as tr.im has demonstrated, and their shutdowns could annihilate your linking history. If you own a domain, though, you can host your own service.

Even if you consider the links you've shortened for Facebook, Twitter, IMs and other services to be just of-the-moment, nothing-serious items that aren't worth backing up, leaving a host of dead links lingering around the net isn't good for anybody, or anybody's searches. There's not a lot you can do about your already-posted social network links, but anyone who's got $10 for a domain name registration, and a creative short URL idea, can host, monitor, and control their shortened links.

We're going to run through a basic installation of Yourls, a server-based webapp that can run pretty much anywhere a WordPress installation can. There are lots of other options, which we'll get to as well, but Yourls is a fairly smart and fast way to get up and running with your own URL shortener.

What you'll need

  • Hosted or DIY server space: That space must be running at least PHP 4.3, MySQL 4.1, and with "mod_rewrite" enabled. In plain English, that's most any mainstream web server an individual pays about $5/month to for basic hosting. For DIY server types, any installation of LAMP on Linux, WAMP on Windows, or MAMP on a Mac. If you're going the DIY route with a Windows system, our guide to setting up and hosting a blog on your computer covers many of the basics of patching your own web-facing system together.

  • A domain name: You'll preferably want something short, which can be difficult in the super-saturated .com/.biz/.net market. You might get inspired and lucky, but you also might need to pay just a bit more for an international top-level domain (TLD)—the part after the period, like .tv, .nl, and the like—which can cost between $15-$90. The URL used in the screenshots up top is an example, albeit not really feasible, unless I figure out how to buy a straight-up Nicaraguan TLD.

  • Access to your server files: Whether you use an FTP client (like one of our readers' five picks), a command line, or your host's web access, you'll need to copy one folder over somewhere on your server.

Setting up

First up, go and download the latest Yourls package, then un-zip it somewhere you can get to it. After that, determine how you can access your server's databases—can you create new, separate databases yourself, or do you only get access to a single spot?

I use 1&1 to host my personal web site, so in my case, that involves heading to my "control panel" at admin.1and1.com, logging in, clicking on "MySQL Administration," then clicking the "New Database" button and naming it "yourls." Your mileage will vary from host to host, but it's likely you can Google around and figure out how to create a new database, or access the one you're given. Copy all those strings of characters for the database's name, host name, user, and password, then head back to where you stashed your Yourls download.

Inside the folder you extracted from the Yourls archive package, head inside the "includes" folder and look for config-sample.php. Open it inside a text editor, and, near the top, you'll find a series of lines asking you to fill in a username, database name, password, host name—all the stuff you grabbed from your host. Replace the default answers for those four settings inside the single quotes on the right, as shown in the picture here.

Farther down the file, under "Site options," look for a line asking for a "Short domain URL." If you've got your own domain name, simply fill it out and be sure to leave off the trailing "/" slash. If, like me, you're putting Yourls in a sub-folder of your existing domain name, fill out the sub-folders and, again, leave off the slash.

Finally, decide whether you want to let everybody and his brother create short URLs through your site, or whether you'll hand out passwords. For the former, open option, simply change the value next to "YOURLS_PRIVATE" to true. For the likely more sensible, password-protected setup, substitute the username and password values just a bit further down the file.

When you're all done with everything, re-save the file with a new name, config.php. If you're installing Yourls in a sub-folder of your domain, you'll need to make one more tweak. In a file named .htaccess in the main Yourls folder (which might be hidden, so enable your "show hidden files" setting), remove the "#" from the beginning of the line, and add in your folder names after the RewriteBase /—in my case, that became RewriteBase /u/, because I installed Yourls at thepurdman.com/u/. Save and close that file.

Your last setup step is to fire up your FTP client, command line, or web access tool and copy the contents of your Yourls folder to your server. Those with dedicated domains can just drop those folders and files into the main access space, or the www section in some cases, while those doing a sub-folder installation should drop them in that folder.

Using Yourls

If the files copied without error to your server, head to where you put them in a browser, followed by /admin/install.php. If your database and configuration files were set up successfully, you'll see a confirmation like the one pictured at left. Head to your Yourls installation site, followed by /admin, and let's make some links.

As you can see above (or click for a larger view), Yourls has a fairly straightforward interface. Type in a long URL, a custom short code, if you'd like, and hit "Generate Short URL" to have your server do its thing. The administrator can edit and delete short URLs created with his domain, and search for existing short links with filters and keywords.

That's about it for Yourls—it's one of those apps that, once you get it working, just works. There are, however, two added tools worth noting: a WordPress plugin that can automate the creation of Yourl-generated short links for each and every post, and a bookmarklet generator for those who don't want to head back to their own site to create new short links.

Other options

Have your own domain, but not paid server space? Are you mostly a blogger who just wants secure links back to your own content? Here's a few avenues to explore:

  • Google Short Links - A "Labs" feature of the free Google Apps domain package. There's no easy-to-install bookmarklet for quick generation, but it does allow for tracking and editing, just like Yourls.

  • su.pr - StumbleUpon's URL shortener, but install-ready for your server space or WordPress installation.

  • Phurl - Another PHP/MySQL-based, DIY shortener package, with a different feel and options.

  • Short URL and Le Petite URL - WordPress-based plugins that auto-generate short URLs for each of your pages and posts.


Got your own way around potentially faltering URL services? Found a neat script, server package, or free webapp that gets your URL shortening done? Tell us about it, and anything else you've tried, in the comments. Thanks to Rufo for the links and tech support!