Results tagged “Web”

Monday, February 15, 2010, at 5:45 PM

This morning, Phoebe and I were talking about stuff, as we are wont to do from time to time, and the topic of URL shortening came up. You know, those services like tinyurl.com and bit.ly that take a really long URL and convert it to a much shorter one. It’s handy for pasting URLs into emails, or tweets, or other spaces where an overly long URL doesn’t fit.

On the other hand, these services do have their drawbacks. For one thing, they are not guaranteed to be permanent; if they go out of business, your links might die along with them. For another, they are used so often by spammers for sneaky redirects that users might be wary of clicking on one of their generated links. Some websites even ban all tinyurl links from their sites, and with good reason.

But, we realized, these problems wouldn’t exist if we had our own URL shortener! And so today I built us one. We now have u.gleeson.us, a URL shortener that we own, and that only Phoebe and I can use. So now I can take really horribly long URLs like this…

http://www.amazon.com/gp/product/1596062266?ie=UTF8
&tag=gleesonus-20&linkCode=as2&camp=1789
&creative=390957&creativeASIN=1596062266

..and instantly convert them to short ones, like this…

u.gleeson.us/6

By the way, that link — both of them, really — goes to an excellent anthology by Jack Vance, one of my all-time favorite authors. Just in case you were curious, but not curious enough to click.

Comments on this entry:

There are 10 comments on this entry.
#1
15 Feb 2010
6:42 PM

Cool! Care to give us any clues as to how you did it? (Appending redirects to an .htaccess file, perhaps?)

#2
15 Feb 2010
6:54 PM

You guessed it! Here is my .htaccess file in its entirety:

RewriteEngine on
RewriteRule ^.+\..+$ - [L]
RewriteRule ^(.+)$ elongate.php?b=$1 [L]

The first RewriteRule just says to let any requests that include a period to pass through unchanged. That way I can still put normal files on that domain, because all filenames have periods. At least, they should.

All other requests go to the second RewriteRule, which invisibly loads a PHP script and passes the request in a query string.

The PHP script, of course, just converts the request (which is in a base-52 numbering system to make it extra short) to an integer, and looks up the URL with that index.

#3
16 Feb 2010
10:48 AM

Wow, how the heck does base 52 work? Are you using non-alphanumerics past 36?

#4
16 Feb 2010
12:19 PM

Upper and lowercase letters, dude. (The URL shortener tr.im uses a base-62 system with A-Z, a-z, and 0-9. So mine is 10 less.)

Here are the glyphs I use:

A-Z, except vowels -- 21 chars
a-z, except vowels -- 21 chars
2-9 -- 8 chars
hyphen and underscore -- 2 chars

That adds up to 52. I left out the vowels (and zero and one, because they can look like O and I) so that my encoded URLs will never inadvertently spell any offensive words in any language. It would be awkward, for instance, if I emailed my dad a link and it was u.gleeson.us/TitS wouldn’t it?

#5
16 Feb 2010
12:53 PM

Aha! Very clever, and it’s good design to avoid the ambiguity of 0 and O, l and 1.

I tried to figure out what you were doing by subtracting 36 from 52, but that’s 16, and I couldn’t figure out what the heck you were using sixteen of.

my encoded URLs will never inadvertently spell any offensive words in any language

You must not speak Klingon.

#6
16 Feb 2010
1:11 PM
You must not speak Klingon.

That’s a pretty good maxim for humans in general.

But come to think of it, Hebrew has no vowels, either, right? Maybe I should have left out the consonants instead.

#7
16 Feb 2010
1:17 PM

LOL.

I have a hard time reading your captcha, by the way. The black text on grainy grey background can be hard to parse. Have you considered recaptcha? It’s easier for humans to solve because words are easier to read than random unpronounceable strings (I’m solving a “zhsust” right now), there’s an MT plugin for it, and it’s even a good cause: people solving your captcha are actually helping to digitize books!

#8
16 Feb 2010
1:30 PM

Well, it’s hardly my fault if you don’t know what a zhsust is. But I do take your larger point. I will use recaptcha instead at my earliest opportunity.

#9
16 Feb 2010
10:24 PM

This is me, Sean Gleeson, but I am not signed in, so I can comment anonymously and test my new reCAPTCHA thingie. If you are seeing this comment on my site, then that means it worked.

#10
16 Feb 2010
10:37 PM

This is awesome, it’s working great!

1
(Thanks for reading all the way to the bottom.)

Sean Gleeson is an artist, developer, writer, teacher, statesman, and family man in Oklahoma City, Oklahoma.

See full profile.

Sean Gleeson Sean Gleeson