Sometimes It's Okay to Point

Mom always said, "It's not nice to point." I'd argue Mom didn't manually enter long, cumbersome URLs, however. We're all familiar with services like TinyURL, but because we're Linux folks, we tend to prefer doing such things on our own. As with almost everything in Linux, there's more than one way to skin a cat, and in this article, I explore a bunch. (Note, I really should Google "skinning a cat", because now that I read it, it's a rather morbid idiom!)


The first step in a URL-shortening solution is the domain name. If you're trying to make short, memorable URLs, it helps to have a short, memorable domain name. It doesn't save much time if you use to shorten up a link half its size. So a short, memorable domain name is ideal. It's also the toughest part of the equation. Sites like can help, but coming up with a short domain name is quite challenging. And thinking of one that is memorable? Even more so. The best I could come up with after an embarrassing amount of time searching was "". It's not perfect, but it makes me chuckle, and it's short.

The other piece of the puzzle is a Web server. The solutions I talk about here vary in their requirements, but most need nothing more than a hosted Web server, nothing fancy. It's helpful to have .htaccess modification access, but if you don't have that sort of control over your Web site, no worries.

iframe—Maybe You Shouldn't Redirect at All

They're not terribly popular anymore, but back in the day when GeoCities was the Web hosting platform most people used, several "domain cloaking" services were available. This basically hid the long, ugly URL by loading it inside an invisible frame. I've done that here:, and you can see a couple glaring problems:

  • The page title is static and never changes when following links.

  • The URL in the address bar also never changes, which makes things like copying a Web site's URL impossible.

  • Sometimes forward and back work as expected, sometimes not.

If those limitations don't bother you, maybe an iframe is all you need, but it's a kludge at best. Creating a page like that is simple, however, so if you want to give it a try, the above example uses the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<h3>This Is Not Google. Or is it?</h3> 
<iframe src=""  width="100%" height="100%" >

PHP, JavaScript and .htaccess Options

Although it may not be the most elegant solution, it's certainly possible to use a custom .htaccess entry to provide a redirect. An entry like:

Redirect /togoogle

will send anyone requesting the /shortcode URL on your site to be redirected to the other site. I've put this into action on my site, so should redirect you to Google. To be honest, this might be all you'll ever need. If you have the rights and abilities to use and modify an .htaccess file on your server, those little one-line entries are quick and dirty, but they work well.

If you don't have the ability to edit or take advantage of .htaccess files, a similar functionality can be attained using PHP or JavaScript. On my server, I created two folders. One called javascriptgoogle and one called phpgoogle. Inside the javascriptgoogle folder, I created a file named index.html containing the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="javascript">

Surfing to will show you the results of that single JavaScript command. Sometimes JavaScript isn't ideal, especially because it's so often to blame for malicious code, and many folks turn off JavaScript in their browsers. In that case, perhaps PHP is a better solution. In the phpgoogle folder, I've created a file named index.php containing the following code:


If you visit, you'll see the results of this PHP code, namely you're redirected to Google's site. If you're keen on entering redirects manually for your short URL solution, it doesn't really matter which method you use. Although for compatibility purposes, the .htaccess or PHP methods might be best, because the work is done on the server side and not by the user's browser.

Getting Fancy with YOURLS

So now that I've looked at the geeky underbelly of URL redirection, it seems like the perfect time to introduce YOURLS (, which is a nifty open-source program that clones the abilities of,, and such the like. I didn't mention YOURLS at the start of the article, because this is a learning column, and I truly wanted everyone to understand how to redirect without fancy crutches like YOURLS. That said, it's a really awesome tool!

YOURLS does some things the scripts and methods above just can't do. Some of its more awesome features include:

  • Public or private mode.

  • Auto-generated or custom-chosen URL keyword (shortcode).

  • Stats, including number of clicks, referrers, geolocation and so on.

  • Plugin architecture.

  • Full AJAX interface.

  • Developer accessible API.

It's also dead simple to install. Create a database with something like phpmyadmin (or the command line if you're geeky enough), unzip the YOURLS archive, edit the config.php file, and enter your database server information. Then visit and log in! Figure 1 shows my admin page for, and it gives a list of example links.

Figure 1. The interface makes adding, modifying or deleting simple. (But, it doesn't work right in Chrome; Firefox seems fine.)

Although the admin interface is a simple way to add and edit entries, one of YOURLS' coolest features is the bookmarklet feature. In the "tools" section of the admin screens, you'll see a section similar to Figure 2, with a few different bookmarklets from which to choose. They all function slightly differently, but they are fairly easy to figure out. I recommend dragging them all to your browser's bookmark bar, so you can see which method you prefer. From that point on, simply clicking the bookmarklet when on a specific page will allow you to shorten the link with YOURLS and give you the custom URL you can share with the world. Figure 3 shows the bookmarklet in action.

Figure 2. The bookmarklets make using YOURLS a breeze.

Figure 3. A popup allows for custom URL creation.

Statistically Awesome

Once you have YOURLS set up, and you've shortened all the URLS you can imagine shortening, the next cool thing to check out is the stats. Much like, with YOURLS you can open the stats page for a particular link by adding a + to the end of the short URL. So for Figure 4, I simply surfed to, and after logging in, I got to look at all the glorious clicks I've received. The information is quite useful if you're looking for how popular your particular shared URLs have become. As mentioned above, the statistics YOURLS generates are quite extensive.

Figure 4. Although my stats aren't impressive here, the actual functionality is pretty awesome.

Where to Go from Here?

YOURLS provides an excellent interface for short link creation. It also offers a simple bookmarklet feature for creating short links on the fly. Thanks to its API, however, the coolest part of YOURLS is that it can be integrated into other programs as well. WordPress, for example, has an excellent plugin (, which integrates into WordPress. Instead of using a third-party URL shortener, WordPress will use your custom YOURLS install with your custom short domain name!

When it comes to URL shortening, or even just simple redirection, there are many ways to accomplish the task. There are also dozens of free redirection services available, many of which offer similar features to YOURLS. When it comes to controlling your data, however, it's hard to beat a solution you host yourself—if you can come up with a decent domain name, that is. Sadly, that's often the most difficult part!


Shawn is Associate Editor here at Linux Journal, and has been around Linux since the beginning. He has a passion for open source, and he loves to teach. He also drinks too much coffee, which often shows in his writing.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The screen capture on the

Cummins Inilne 5's picture

The screen capture on the bottom shows that the vehicle will not start. The voltage values are normal, rpm is greater than 120, sync from the FICM is normal. The ICP is below 500 psi and the Inj Press Reg has reached 85%, which means there’s an issue in the oil system.

sometimes it is really easy

russian fur hats's picture

sometimes it is really easy and sometimes it seems to be very hard to point i guess. . .

Reply to comment | Linux Journal

Visual Impact Reviews's picture

Greetings! Quick question that's totally off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone 4. I'm trying to find a template or plugin that might be able to correct this
problem. If you have any suggestions, please share.
With thanks!

Your post will be rather good

Annabelleclara's picture

Your post will be rather good and I'm sure some will find it interesting because it's about a topic that's as widely discussed as others. Some may even find it useful.Thanks so much for your post.

I make URL short by using

home page's picture

I make URL short by using free online software, I do not know do it any effect in the search result page from SEO perspective?

This is really nice. Thanks

lisaedward's picture

This is really nice. Thanks for sharing .
Flying car

Reply to comment | Linux Journal

jamon serrano's picture

Heya outstanding blog! Does running a blog similar to this require a
massive amount work? I've no knowledge of coding however I was hoping to start my own blog soon. Anyway, should you have any suggestions or tips for new blog owners please share. I know this is off topic nevertheless I just wanted to ask. Appreciate it!

Cheap Oakley Sunglasses,Sale Replica Sunglasses,Oakley Confront

podcfzu8's picture

Many fashion designers have begun large-scale production of sunglasses, every designer's commitment to high quality and unique framework for consumers to consider.Oakley lenses and sunglasses, in the summer they intend to let men and women can be seen fantastic visual.Many people now choose only the pursuit of stylish appearance does not have UV protection sunglasses This sunglasses has been classified as low-quality sunglasses, in fact, strictly speaking, none of these glasses can be called sunglasses.Oakley sun shades with any devout pursuit involving athletes Oakley Outdoor jackets and Oakley to protect your eyes.Hollywood star trend and fashion runways in the optical industry and consumer behavior statistics do not need glasses in the crowd.The lens frame connector sunglasses for larger nose, if the frame does not touch the nose, and the framework itself smaller sunglasses, the better.Tinted lenses filter out a large number of blue, you can improve the visual contrast and clarity, in the case of air pollution or foggy wear better.Qualified sunglasses also block ultraviolet rays. Currently on the market with 100% UV logo sunglasses, show that testing by the China Institute of Metrology, some fabled.Low-quality sunglasses is completely different, not only block UV performance is not strong, the coating easily damaged, but also the lens transmittance serious decline, eyes like objects seen in the dark, the pupil will become large residual UV it will be a substantial injection eyes, eye damage.With sunglasses in his hand corners facing the fluorescent light, so that the reflective mirror smooth scrolling, mirror reflection of the fluorescent film appears wavy, distorted shape to prove that the lens is not flat, so that the mirror can damage eyesight.Oakley sunglasses you expect the world leader in performance and innovative technology, unparalleled processing to the smallest detail, no trouble, just change a new lens group.The polarization angle and curvature of the lens through professional design and processing, the wearer does not have scene distortion and feeling of vertigo, lightweight resin polarized lenses have the advantage of easily broken, easy to wear and comfortable. The most suitable for fishing, driving, sports, sailing, skiing, hunting and other occasions.Sunglasses resin lens material is a phenolic structure of chemical substances, the biggest advantage of the resin lenses that are very light, high temperature, impact resistance, can effectively block ultraviolet rays.Oakley sunglasses lenses excluded skin oils, so the lens is smear-resistant, easy to keep clean.Fashion magazines and runway shows, designer eyewear accessories with their plans - that does not belong to sunglasses - either clear lenses or only slightly tinted color lens.Oakley glasses legend, with their beauty and complexity, is a fantastic personal preference. All of these in the sun, often originally depicted VIP.Oakley is incredible tonal range, whether you look at the style-based, or a sports-oriented sunglasses, one that suits your needs!Specifically for the framework of the Asia, you can choose to increase the nose pad design, more suitable for Asian face, make the wearer more comfortable height.You should choose your personality and preferences, as well as your requirements, according to the color of the lens. It is very important for you to choose.Excellent sunglasses, there has been a lot of features to provide comfort and excellent level into its rich supply of lower prices sunglasses provide 100% satisfaction guarantee follow-up 30 times to buy.

Reply to comment | Linux Journal

How To Read a Man's picture

It is perfect time to make some plans for the future and it's time to be happy. I have read this post and if I could I wish to suggest you few interesting things or tips. Maybe you could write next articles referring to this article. I wish to read even more things about it!

Reply to comment | Linux Journal

Cheap Air Tickets's picture

Pretty nice post. I just stumbled upon your blog and wanted to say that I have truly
enjoyed surfing around your blog posts. After all I'll be subscribing
to your feed and I hope you write again very soon!


Hans Tielbeek's picture

Great post. Really usefull

Reply to comment | Linux Journal

Natural Clear Vision Scam's picture

I read this paragraph fully on the topic of the comparison of latest and earlier technologies,
it's remarkable article.

Reply to comment | Linux Journal

work from home positions's picture

Wow! After all I got a weblog from where I be able to in fact get helpful data concerning my study and