Author Topic: Shorten Your URLs  (Read 1236 times)

0 Members and 1 Guest are viewing this topic.

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Shorten Your URLs
« on: September 13, 2013, 09:18:59 AM »
With the growing need to post URLs on social media and with many websites creating their own shortening protocols, I thought I would give you some tips on how to use the CSV scripts to make your URLs as short as possible.

First, using your csvread script, change its name. You should in good practice do this anyway since spambots know the csv suite all too well. Rename your csvread (or csvsearch) to index.pl. This allows direct call access to the directory folder level of your script's location. For example, it would simply be cgi-bin/ instead of cgi-bin/csvread.pl.

Second, get out of the comfort zone of your cgi-bin. Most hosting companies allow you to use a small .htaccess code to turn any directory into a directory that can execute cgi scripts. I usually create a directory simply named "c". An example of a .htaccess file that you can add to this directory to execute cgi or perl scripts is this:

Code: [Select]
Addhandler cgi-script .py .pl .cgi
Third, make sure your host mirrors your files for both direct URL and the www subdomain. This means you can use http://yourdomain.com instead of http://www.yourdomain.com.

Last, you may want to change your csvwrite script, or if you are not using csvwrite to create data entries make sure you have a database with a unique ID field. If using csvwrite, you can use this hack: http://www.ezscriptingforums.com/index.php?topic=491.0. I recommend using the alphanumeric hack to make the ID letters and numbers and shortening the ID to only hold 6 characters. That leaves only a 1 in 57 billion chance of duplicating an ID.

Now you can create a shortened URL by calling: http://yourdomain.com/c/?ID=123456 in stead of http://www.yourdomain.com/cgi-bin/csvread.pl?ID=123456. That saves you 21 characters in the URL. There are other hacks you can do to the script to shorten this even more, like renaming the ID field to a one character name, like "I".

There are other simple techniques you can use browser side like javascript that looks at the last characters in a URL string and redirects. You can set that up on a per directory basis as well.

Jason
Founder of www.slipdex.com

Offline Paul

  • Hero Member
  • *****
  • Posts: 162
Re: Shorten Your URLs
« Reply #1 on: February 28, 2014, 07:20:34 PM »
Great idea Jason! Thanks.