WillMaster Possibillites Logo EzineSeek Award
Short URLs and Redirection
Without CGI

by
William Bontrager

Permission is granted to reprint the article below in its entirety provided no changes are made to the article text and the author's name, signature lines, and copyright line are printed with the article. However, you may change the article's title.

The template is short and simple. You can put it anywhere on your site a regular HTML web page would go.

It provides for browsers which are and are not JavaScript enabled; and which are and are not META "Refresh" tag enabled.

You can turn long URLs into short. For example, instead of publishing http://www.amazing.com/associate.cgi?ref=1241&more=1421&u=me you can publish http://yourdomain.com/amazing/

Just change the target URLs in the template into your long URL, rename the template page index.html, and upload it into your /amazing/ directory.

That's it.

Whenever someone clicks on your short URL they will automatically go to your long URL.

It's kinda like magic. And you don't even need CGI!

Just follow the instructions.

You can use the same technique to prevent directory listings in browsers. That's what can happen if you don't have a default page in the directory. (The default page is usually index.htm or index.html) Put a redirecting page into the needy directory. The target URL can be your home page.

Are you involved in several associate programs? Make a separate directory for each. An /amazon/ for books and a /borders/ for software and a /otherstuff/ for other stuff. Then make a default page for each of those directories using the template page provided here. The target URL for the default page is your unique associate URL.

You can use a similar technique to get an exact hit count for different promotions or advertising campaigns -- banner, ezine, whatever. Each ad or series of ads points to a unique default page. And the default page redirects the visitor to the target. (You'll need access to your server logs for this to provide meaningful statistics -- or some other means to count hits on the default page (maybe the target page can provide a referral count).)

The redirecting page does not need to be your default page. It could be http://yourdomain.com/money/amazon.html or http://yourdomain.com/money/borders.html or http://yourdomain.com/money/otherstuff.html

Got your own ezine? Want all your associate links to point to your own domain? Now you know how!

Those are some ideas.

Write to me at subscribe-possibilities@willmaster.com and let me know what other ideas you come up with for using the simple redirecting page.

Now, the instructions:

If you are reading this article with an HTML email program or AOL's default email client, then you may need to "view source" in order to see the HTML source code. As an alternative, you can read the archived article in your browser. The archives are at http://www.willmaster.com/possibilities/archives/

The template is also provided in the "Other References" section of http://www.willmaster.com/possibilities/examples.html

The HTML template provides redirection in three ways:

(1) With the META "Refresh" tag -- one second delay.

(2) With JavaScript -- speedy.

(3) A visible link -- mouse click required.

(1) and (2) are placed between the <head> and </head> tags of your page. (3) is placed between the <body> and </body> tags.

If the browser is JavaScript enabled, (2) will take over. Otherwise, the "Refresh" tag will be the operating method.

If the browser is neither JavaScript nor META refresh tag enabled, the visitor will see a link to the target URL labeled, "click here".

Start with a bare-bones HTML page:

<HTML>
<HEAD>
</HEAD>
<BODY>
</BODY>
</HTML>

~~~ (1)
Place the following between the <head> and </head> tags (replace http://target.url/ with your target URL):

<META HTTP-EQUIV="Refresh" Content="1; URL=http://target.url/">

~~~ (2)
Place the following between the <head> and </head> tags, below the "Refresh" tag (replace http://target.url/ with your target URL). (JavaScript is line-break sensitive.):

<script language="JavaScript">
<!--
window.location = "http://target.url/"
// -->
</script>

~~~ (3)
Place the following between the <body> and </body> tags (replace http://target.url/ with your target URL):

<noscript>
<center>
<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;
<p><a href="http://target.url/">click here</a>
</center>
</noscript>

Notice the <noscript> </noscript> tags. This prevents a JavaScript enabled browser from displaying the text. It thereby saves a nanosecond or two, which can mean faster redirection.

If the visitor's browser is neither JavaScript nor META "Refresh" enabled, the page waits for visitor action.

Of course, if you know your visitor's browsers with adequate certainty, you may eliminate any of (1), (2), or (3). In most cases, though, all three methods should be provided for.

Here is the complete HTML template (replace all instances of http://target.url/ with your target URL):


<HTML>
<HEAD>
<META HTTP-EQUIV="Refresh" Content="1; URL=http://target.url/">
<script language="JavaScript">
<!--
window.location = "http://target.url/"
// -->
</script>
</HEAD>
<BODY>
<noscript>
<center>
<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;
<p><a href="http://target.url/">click here</a>
</center>
</noscript>
</BODY>
</HTML>

If you need help, write to me.

Copyright 1999 by William Bontrager

William Bontrager, Programmer and Publisher
"Screaming Hot CGI" programs
"WillMaster Possibilities" e-Newsletter
http://willmaster.com/possibilities/
subscribe-possibilities@willmaster.com