Home

How To Create Your Own URL Shortening Service

Comments | Steve Krause, BYTE | September 21, 2011 03:45 PM

Category: Freeware

If you've ever tried to chop down a 160-character tweet, you know how handy a URL-shortening service can be. With only 160 characters, every character counts.

Public URL-shortening services like bit.ly and is.gd are great for the average Twitter user. But if you're a serious blogger or company seeking to manage your brand online, you should definitely think about creating your own shortening service. That way you'll be able to protect your brand and better analyze traffic.

It only takes about 15 minutes to set up your own URL shortener. Here's how to do it. First, come up with a short but similar domain name. For this, I use the website http://domai.nr. Domain.nr lets you type in a word or name and do everything you need to register your new, shorter domain name.


Once you have that new short domain, download the latest copy of YOURLS.

Extract the downloaded file to a new subdirectory.

Now, navigate to the /includes folder and copy the file sample-config.php to /user/config.php. Open the config.php with your favorite text editor. You'll need to edit a few files before you upload it to your hosting provider.

Configure the database settings. Fill in the MySQL settings you will be using with your hosting provider. I highlighted the most critical of the settings you need to configure. Fortunately, the config file has some great comments that will make it easy for you to get through the process.

Now scroll to the bottom of the file to complete the configuration, including the site name, cookie key, and user password to log in. Be sure to create a password that's long and stronger than the one I use in the example below. That means a combination of numerals and uppercase and lowercase letters.

YOURLS is a simple .php /MySQL application; pretty much any hosting provider will work with it. Just grab your folder and upload it to the root of your new domain you purchased. In my example I'm uploading YOURLS to a subfolder off the root of my domain.

Now it's time to create the MySQL database YOURLS will use to store all the data in. Using the MySQL settings from the config.php file you created earlier, create your MySQL database on your host. On my host, this step is fairly easy. It will vary depending on your hosting provider. Check with your provider if you need help with this step.

Once your files are all uploaded and your MySQL data is configured, navigate to your new site and click the Install YOURLS button on that page.

If you did everything correctly, you should get a screen full of green check boxes.

Enter the Username and Password you configured earlier in your config.php file.

Optional: Once logged in, I recommend you enable hyphens. Under Allow Hyphens in Short URLs, click Tools and Activate.

Now it's time to test out your new service! Click the Admin Interface Link at the top of the page and then type in a URL and Custom short URL.

One of the great things about YOURLS is its reporting capability. Once you have created your short URL, just click the Report button at right to view everything from traffic stats to traffic sources.

Another way to get stats is to navigate directly to the page and add a + at the end of it.

YOURLS also comes with several different bookmarklets that let you easily shorten any webpage you visit. Just head over to the Tools page. Click and drag the bookmarklets to your browser's toolbar.

Now visit any website and click the bookmarklet to automatically create a short URL for that page. Remember you need to be logged into the YOURLS site for the bookmarklets to work.

If you're a blogger who uses Wordpress, you also should install a free plugin that will automatically create a shortened URL for each post you publish. It's possible to configure that plugin to automatically publish each post with the short URL to Twitter, too. Because YOURLS is based on PHP and CSS, it's super easy to configure.

Based in Seattle, Steve Krause is a senior contributor at BYTE. Follow him @krausesteve and email him at Steve.Krause@BYTE.com.



Related Reading




Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

BYTE encourages readers to engage in spirited, healthy debate, including taking us to task. However, BYTE moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing/SPAM. BYTE further reserves the right to disable the profile of any commenter participating in said activities.

COMMENTS

Tune In to BYTE
Facebook Twitter LinkedIn Newsletter RSS
Whitepapers
whitepaper
In this paper you will learn the five trends shaping the future of enterprise mobility. Learn how the rise of social media as a business application, the lurring between work and home, the emergence of new mobile devices, the demand for tech savvy employees and changing expectations of corporate IT will fundamentally change the workplace.
whitepaper
In a survey of more than 1,700 information workers (iWorkers) in North America, notebooks, desktops, and smartphones were found to be “must-have” devices, while tablets, slates, and netbooks were relegated to “nice-to-have” status, according to a commissioned study conducted by Forrester Consulting on behalf of Dell and Intel.
Sponsored by: Dell
Upcoming Events