A better small URL generator: fitting URL

This article was written in 2009. It might or it might not be outdated. And it could be that the layout breaks. If that’s the case please let me know.

UPDATE: You probably shouldn’t use this script. Try another result in Google please.

The last few weeks I used my small URL generator a lot. I even bought a new, smaller, domain for it to make it a bit more useful. For Twitter it’s perfect. But when using it in e-mails I got some complaints. People are happy that all links are clickable (some mail programs cut of every line after an x-amount of characters, leaving many long URL’s unclickable) but there was no information about the link left in the new, small URL. So I decided to change the script.

There are now two bookmarklets to call it. One is for twitter and will return a simple small URL. The other one is for e-mail and will return a url that consists of the title of the page you’re linking to but it’s smaller than 66 characters in total, which seems to be enough. (Replace ‘http://example.com/a/fitting-url.php’ to your domain and your script name and location in these bookmarklets).

Now, what the script does is first it checks to see if the title is given. If no title, the script assumes you need a small URL. It will check if the original URL is smaller than the result. If so it will return the original URL, selected, ready for you to copy. If not, it will generate a new small URL, write it to the .htacces and return it, selected, ready for you to copy.

If there is a title given the script assumes that you want a URL for e-mail. It will check if the original URL is smaller than 66 characters (the amount of characters I decided to use, you can change that in the script). If so it will return the original URL, selected, ready for you to copy.
If not it will remove all non-alphanumeric characters from the title, convert it to lowerspace, replace spaces with dashes and add it to your domain name, write it to the .htacces and return it, selected, ready for you to copy. And yes, there is a check in here to see if a URL already exists. The URL it returns will always be unique. This is because some sites have lousy titles, like a long sitename at the beginning of a title or the same title on every page.

Enough talking. You can download the fitting url script here. Put the script and the a.htaccess (rename it to .htacces) in a directory of your choice, edit the first three lines of fitting-url.php, rename the scriptlets as needed and you’re ready to go.
I wouldn’t make the URL to the script available to the public. Being able to change a .htaccess file seems a bit like a security issue…

Please do leave feedback and don’t hesitate to correct my PHP. I’m not a coder, I use google to write scripts.

Comments

    • Vasilis
    • #

    LOL!