Oct. 13th, 2009

marnanel: (Default)
Tired of tinyurl?  Worried that whatever other shortening service you're using might go away one day?  Want to get yourself a little more autonomous?  Here's how to run your own damn URL shortening service, in three easy steps.
  • This is slightly more interesting if you have a short domain already, like rhmt.org.
  • This is a string-and-chewing-gum system you can set up in two minutes, and it's clearly not going to scale well if you have thousands of URLs to shorten; by that time, you can replace it with something heavy-duty.
  • We are also banking on the fact that you don't have any valid URIs in your domain which entirely consist of capital letters (http://example.com/WOMBATS).
Recipe:
  1. stick this PHP script in the root of your website. (I'm not a big PHP fan, but you know it'll work anywhere.)
  2. create a file "shorten.txt" with the URLs you want to shorten in it, one per line. Put that in the same directory.
  3. edit your Apache httpd.conf and add the lines
    RewriteEngine on
    RewriteRule ^/([A-Z]+)$ /shorten.php?u=$1
And restart Apache. Now go to http://example.com/shorten.php?list=1 and you will see a list like this:
http://example.com/A  http://www.gnome.org
http://example.com/B  http://borrowable.net
http://example.com/C  http://shavian.org.uk/xkcd/
The links on the left will then go to the destinations on the right. Just edit shorten.txt to add some more.

If you don't like the idea of people being able to list all your shortened links, change the filename to something other than "shorten.txt" and the
if ($_GET['list']) {
to check for some other parameter that only you know.

That's all.

Profile

marnanel: (Default)
Monument

January 2022

S M T W T F S
      1
2345678
9101112131415
1617 1819202122
23242526272829
3031     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 11th, 2025 12:39 pm
Powered by Dreamwidth Studios