Tame Long Yahoo! URLs

With an eye for URLs and the right tools, you can shorten long Yahoo! URLs when you need to send them via email.

Most of the time, we’re all surfing the Web in virtual isolation. It’s just you and the computer, and the last thing on your mind is the length of a URL at a page you’re visiting. But as soon as you want to share the piece of the Web you’re viewing with someone else, the length of a URL becomes important.

Because email programs wrap text at 72 characters (for easy reading), any URL that’s longer could be broken. A broken URL means someone on the other end of the message won’t be able to see the page you’ve sent them—or that they will have to spend a minute or two pasting the URL together in Notepad. And imagine trying to handwrite a note to someone that includes some of the URLs you stumble across!

Trimming Yahoo! URLs

Yahoo! has a lot of great content to share with others, but some of the URLs are definitely too long to send via email. Here’s a Yahoo! Local URL for a page that shows a list of coffee shops in Sebastopol, CA:

	http://local.yahoo.com/results;_ylt=AvyPaC0wOiCme6J1PYb56tSHNcIF;_
	ylu=X3oDMTBtbGZ2dXFpBF9zAzk2NjEzNzY3BHNlYwNzZWFyY2g-?stx=coffee&
	csz=Sebastopol%2C+CA&fr=

Those 154 characters in the URL are definitely past the 72-character safe zone. If you take a look at the URL, you can see some variable/value pairs that contain the relevant information. The string ?stx=coffee looks important, as does csz=Sebastopol%2C+CA. But the rest of the URL looks like gibberish.

Tip

It’s important to note that what looks like gibberish is actually useful information to Yahoo!, but it’s not useful to you when you’re trying to share links, so you can cut it out.

Cutting the garbage characters out of the URL will give you something more manageable:

	http://local.yahoo.com/results?stx=coffee&csz=Sebastopol%2C+CA

If the area you want to search is small enough, you can even use a Zip Code instead of the city and state combination:

	http://local.yahoo.com/results?stx=coffee&csz=95472

The 51 characters in this URL are well within the safe zone, and the URL points to exactly the same page. If you frequently find yourself sharing pages from Yahoo! Local, you might want to pick up a bookmarklet by Brian Cantoni (available at http://www.cantoni.org/2005/06/06/ylocal) that automates the process of removing the garbage characters. Drag the bookmarklet link to your toolbar, and click it anytime you want to share a link to Yahoo! Local. The bookmarklet opens a new email message with a shortened URL as the text of the message. From there, you can compose your message and share the link without fear of a broken URL.

Even URLs that seem short enough can be just over the limit. Here’s a page of Yahoo! Search results for Brevity is the soul of wit:

	http://search.yahoo.com/search?ei=UTF-8&fr=sfp&p=Brevity+is+the+soul+of+wit

The 75 characters in this URL are barely over the limit. But you can do some trimming here to bring it back under 72 characters. By cutting the URL to its bare essentials, you can get the same search results page down to 59 characters:

	http://search.yahoo.com/search?p=Brevity+is+the+soul+of+wit

When you’re ready to share a URL, keep an eye out for ways to trim the URL down to size. But there will be times when the only option you have is a URL-trimming service.

URL-Trimming Services

The scourge of long URLs is so rampant on the Web that several free services have appeared to help you share even the most insanely long URLs with others. To see how these services can help, here’s an example of a Yahoo! Maps URL that points to a page with driving directions from San Francisco, CA, to the O’Reilly offices in Sebastopol, California:

	http://maps.yahoo.com/dd_result?newaddr=&taddr=1005+Gravenstein+Hwy+N& 
	csz=San+Francisco%2C+CA&country=us&tcsz=Sebastopol+CA&tcountry=us

As you can see, this 135-character URL is dense with information. There’s nothing extraneous we can strip out to get the same information. This is where TinyURL.com can help. Copy any long URL you’d like to abbreviate and paste it into the form on the front page at http://tinyurl.com. Click the Make TinyURL! button, and the next page will give you an abbreviated URL, like this:

	http://tinyurl.com/b356b

These 24 characters are well within the safe zone and definitely won’t break in an email. Another service, available at http://shorl.com, produces the following URL:

	http://shorl.com/disaprigrohegi

Each of these services stores the long URL on its server, assigns the URL a random character string, and redirects to that long URL when someone visits the short address. Shorl.com even provides some usage statistics, so you can see how many people have used the shortened URL.

There are some drawbacks to using these third-party services. The person you’re sharing the link with won’t know what site they’re actually going to visit. This might make for some fun practical jokes, but it’s always better to be as direct as possible when sharing URLs with people. Also, the longevity of the link isn’t guaranteed. If TinyURL.com or Shorl.com goes out of business tomorrow, your link will fail. Using redirection services like these isn’t the best choice if you’re going to print a URL in a book, for example. But for casual use, these services are a good way to share long URLs without annoying the person on the other end.

Get Yahoo! Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.