What is URL Shortening? A way to truncate long URL addresses so they are shorter in length. Why would one shorten a URL? They are easier to share! Twitter for example, has a 140-character limit on messages. Shorter URLs mean you can add more text to your tweet.
There are many URL shortening services available, such as bit.ly, ow.ly, is.gd, and Awe.sm. Each has its own take on URL shortening and works adequately. I was looking for specific features in a URL shortener.
1. Self-hosted – Shortening services are a dime a dozen, who knows how long they will last. For example the short lived bieber.ly was up for less than a week. I want to be able to access the archive of URLs I have shortened and shared.
2. Personalized – When I share links I want them to be part of my “personal brand.”
3. Analytics – I want to see the reach of the links I share. Click count, referrer location, and geographical statistics.
4. Client integration – Currently I use TweetDeck on both my desktop and laptop. On my iPhone I use the native Twitter client. I want links I share from any of my devices to come from the same service.
5. WordPress integration – After I publish a blog post the last thing I want to do is more work. A service that will automate link shortening and sharing is key.
6. Free – Self explanatory
YOURLS really meets my every need. It is loaded with features such as:
1. Sequential or custom shortened links.
2. Bookmarklets that make it simple to shorten links right from your browser.
3. Analytics that include historical reports, referrer tracking, and visitor location.
4. Simple and clean AJAX interface.
5. WordPress integration.
6. API which allows for Twitter client integration (Specifically TweetDeck and Twitter for iPhone).
7. Easy to install.
I have been using YOURLS for about 10 months now and love it. In those 10 months, I have shared 96 links and had 3,296 clicks. There is some room for improvement, especially with the analytics. The YOURLS road map states a plan for Google Analytics support, but unfortunately there is no ETA.
Before you get started, you will need a domain name and a web host. I run my YOURLS setup off my HostGator account and purchased my domain with NameCheap. Since Twitter limits tweets to 140 characters, it is best to use a short domain name for your YOURLS installation. If you need assistance coming up with a short domain name try the free search tool domai.nr.
If you are not using HostGator, make sure your webserver meets the following requirements:
1. mod_rewrite enabled
2. at least PHP 4.3
3. at least MySQL 4.1
*WordPress and YOURLS cannot be installed in the same directory. For example, if your blog is www.blogblog.com your YOURLS installation will need to be something like www.blogblog.com/yourls.
*For the purpose of this tutorial I will be installing YOURLS to www.zachgeek.com/y/. This means any links I shorten will look like www.zachgeek.com/y/abc/.
*I will also discuss how to remove the www. so your shortened URL will be 4 characters shorter.
*Finally I will be assuming you are using HostGator or similar web host with cPanel access.
Install & Configure YOURLS
Step 1: Download and Unzip YOURLS
Download here. Once the download has finished, unzip the files to your local machine.
Step 2: Setup MySQL database and user
Log into your cPanel. The address is normally http://www.yourdomain.com/cpanel/.
Click MySQL Databases
Enter MySQL Database Name
Create MySQL User
Grant User All Privleges
MySQL Database Setup Complete
Step 3: Modify YOURLS configuration file
Browse to where you downloaded YOURLS in Step 1. Open the includes folder and rename config-sample.php to config.php. Now let’s open the config.php and make the changes. I am attaching a screenshot of my config.php and the changes I made to coincide with the database I created above. I have removed some of the developer’s comments and replaced them with my own to help explain some of the options. Other parts are self explanatory. The file you downloaded will look a little different.
Step 4: Upload files
Upload the files to your web host. For example, I will be uploading my files to /home/zachgeek/public_html/y/
Step 5: Install and setup database
Browse to your new installation.
Step 6: Remove www. from shortened links (optional, but recommended)
You can force your webserver to remove www. from your shortened links. This will save 4 characters on your links and it is really easy to do. You can download my .htaccess file here. Make sure you modify it for your domain and directory. Then upload it to your YOURLS directory.
Once you do this your shortened links will look like this: zachgeek.com/y/abc1 instead of www.zachgeek.com/y/abc1.
Note: If you are not installing YOURLS to a subdirectory, your .htaccess file will be different. You can find the instructions here.
I hope this How To helps you create your own URL shortening service! Please feel free to leave questions and comments below and I will try my best to assist.