No.1 | | 2310 bytes |
| 
William Krick (wkrick@gmail.com) wrote:
: I'm experimenting with creating a tinyURL type of service for use on my
: own website.
: I understand the mechanics of putting the URLs in a database and using
: a hash as a key into the database. The part I don't understand is how
: the URLs that are created by some of the services work.
: For example, what I have working so far using php creates URLs that
: look like this
:
: However, some of the free services that I'm emulating have much shorter
: URLs and I'm not sure how they work. Most of them somehow map what
: looks like a folder name to the database key. notlong.com somehow uses
: subdomains, and makeashorterlink.com uses what looks like http get
: parameters but there's no name=value, just a key after the question
: mark. See examples below
Various things come into play.
-1-
The normal way a web server works is that a path may not exist, but a cgi
script does exist with a shorter name, and so that script is run with the
rest of the path as input (i.e. an environment variable, you'll have to
look up the name)
E.g. simple case
exists and is a cgi script
so you can use the following
script.cgi is run, and "/more/path/info" is available as an input.
If you configure the web server correctly then the script doesn't need to
be in cgi-bin, and also doesn't need the .cgi extension. If you examine
your apache config file then you will probably see examples of how to do
this already there, but commented out. So, in that case could use
and again the script (now called "script") will be run with
"/more/path/info" as an input.
-2-
to completely remove the script name from the path you configure the
server to simply pass all requests to the same script, though I'm not sure
off hand what the configuration would be. Perhaps rewrite each path to
include the script name.
-3-
to add a subdomain (e.g. ) is harder.
Not harder really, but less likely to be possible for you. You need to
add an entry into the DNS server that services the domain name. That is
nowe technically dificult, but most of us don't have easy access to do
that.