Roll Your Own URL Shortener with WordPress in less than One Hour
With the closing of the tr.im url shortening service yesterday, many users are beginning to worry about what will happen to all of their shortened URLs.
The reality of the situation is that many almost every social media service – including twitter, friendfeed, jaiku, indenti.ca, etc, etc – all rely on URL shortening services. (After all, it’s hard to have short messages with long urls, right?) But if those services cease to exist, many of the links that have been cultivated, traded, and broadcast will cease to function. In other words, all of your tweets & posts could ultimately become lost or broken links.
The solution? Create your own URL shortening service using WordPress!
Not only will you you ensure that your links don’t become broken or rot, but you’ll also have complete access to click-through statistics, be able to custom tailor the link name & appearance, and you can harness the power to promote your own brand!
It’s surprisingly simple (and cheap!) to build your own URL shortener, especially if you are already familiar with installing & hosting your own copy of WordPress.
HOW TO CREATE YOUR OWN URL SHORTENING SERVICE USING WORDPRESS IN LESS THAN ONE HOUR
1. Purchase a short url online using any domain registry (such as GoDaddy, Register.com or Network Solutions). I suggest searching for a registrar in the event that one is having a domain sale, but you may also want to use your existing web host provider. The domain should be as short as possible – up to four characters – followed by .us. Even a nonsensical name (ie. 42i.us) is great since your priority is to be as short as possible.
2. Set up the domain hosting in your webhost’s domain control panel. (Please note that it may take up to 48 hours for your new domain to work correctly.) You will want to point the domain to a new directory within your public_html folder. For this, I suggest creating a new folder & naming it the same as your new domain, minus the period. For example, “421us”.
3. Download and install the most recent version of WordPress in your newly created directory. (Please note that this tutorial will only work with a new install of WordPress!) In your new blog’s privacy settings, select “I would like to block all search engines…” and finish the installation.
4. After install, log into your new WordPress and edit SETTINGS > GENERAL as follows, replacing “yourdomain.us” (below) with your newly purchased domain name:
WordPress Address (url): http://yourdomain.us/wordpress
Blog Address (url): http://yourdomain.us
This step will ensure that WordPress looks for a domain level index – as described in the “Giving WordPress its own Directory” tutorial – so we must make one adjustment to the wordpress install.
5. Open the “wordpress/index.php” from the wordpress download and change the blog address to match the “Blog Address (url)” from step 4 (above). Save & upload the file into your root new domain’s root directory (ex. /421us/index.php).
6. In the WordPress Admin, change SETTINGS > PERMALINKS to a custom structure. Set the custom permalink to /%postname% so that a new “post” would become http://42i.us/myfirstpost rather than http://42i.us/archives/myfirstpost.
7. Download this redirect theme and edit the “redirect_engine/index.php” on line 9 in a text editor so as to redirect random visitors away from your new blog to a destination of your choice – perhaps your “regular” blog…
Change header( "Location: http: â€¦ "); to
header( "Location: http://yourregularblog.com");
Save your work, upload the redirect theme to your “/wordpress/wp-content/themes/” just as you would any other theme, and activate the new theme.
8. Click on your WordPress TOOLS menu and drag & drop the “Press This” bookmarklet onto your browser’s bookmark bar. This will allow you to quickly create short URLs linking to any webpage by clicking the “Press This” bookmark and changing the post title to the short link of your choice. For example, to create a short URL link to this page, click the Press This and Change the post title to “rollown” (for example) and press Save. To immediately access your short URL, click through to view post or simply right click on the “View Post” link and copy the link URL. The resulting short link should resemble “http://42i.us/rollown” if working correctly.
AND YOU’RE DONE!
Want to take your short URLs to the next level with link statistics and Twitter This options?
To enable to the Twitter This functionality, find the “press-this.php” in the “/wordpress/wp-admin” directory and rename it as “old_press-this.php”. Upload the “press-this.php” from the redirect theme into the “/wordpress/wp-admin” directory. You’ll now have a Twitter This option when you use the Press This bookmarklet.
For short URL link statistics, upload the “wp-shortstat.php” file included redirect theme download into the “/wordpress/wp-content/plugins/” directory, then activate in the WordPress Admin console under “Plugins” as normal.
Did this solution help you roll your own URL shortener with WordPress in less than one hour? Please tweet this post!