You have been redirected to - find out why and how!
Pepper Spray &
Stun Gun Specials!
 CoverYourASP --> How I moved to CoverYourASP

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
38 active users
1625 visitors today
1909 pages today
how is this done?
Tools I use

Copyright © 1999-2011 James Shaw.
All rights reserved.

RSS submissions

Now open source with SourceForge!

As I've mentioned here, by the end of August 2000 the time had come to move my ASP examples from my personal home page at to this new domain -

This article describes the simple measures I took to ensure that people were seamlessly redirected, and even welcomed on the new site!

The first decision I made was to use my 404 handler to trap the pages that had been moved. I could have replaced the moved files with ones containing a redirect, but I decided not to - I hate duplicate code. If I had made a mistake in the redirect code I would have to change it again in each file.

So instead I set up my 404 handler to redirect. The code I used is shown below:


// ============================================
// handle all HTTP 404 errors (File not found)
// ============================================
function Handle404 ( )
   // get the URL that failed - the syntax is "/404http//wwwShawThingcom/missingfile.htm"
   // or, on my machine, "/404http//localhost/missingfile.htm"
   var sMissingPath = "" + Request.QueryString ( );

   // strip off everything before the last /
   var nLastSlash = sMissingPath.lastIndexOf ( "/" );
   var sMissingFile = sMissingPath.slice ( nLastSlash + 1 );

   // if its a file that moved to CoverYourASP, redirect quietly

   // make lowercase first
   sMissingFile = sMissingFile.toLowerCase ( );

   // split into filename and extension
   var sParts = sMissingFile.split ( "." );

   // the new filename on CoverYourASP
   var sNew;

   switch ( sParts [0] )
   // these files were renamed during the move...
   case "about":
      sNew = "/AboutASP.html";

   case "coveryourasp":
   case "work":
      sNew = "/default.html";

   case "workmusts":
      sNew = "/Reources.html";

   // these files kept the same name
   case "404descr":
   case "blank":
   case "browsers":
   case "categories":
   case "categorypage":
   case "columns":
   case "com":
   case "com_2":
   case "contact":
   case "date":
   case "debug":
   case "formatnews":
   case "fso":
   case "generic":
   case "getnews":
   case "getnews2":
   case "getnews3":
   case "getnews4":
   case "getrawnews":
   case "howtorecommend":
   case "LinkToSite":
   case "mailtolist":
   case "mapaddress":
   case "metatags":
   case "oninitialupdate":
   case "public":
   case "recommend":
   case "resultspage":
   case "rotate":
   case "ssi":
   case "subscribe":
   case "uploadnews":
   case "whatsnew":
   case "wider":
      sNew = sMissingFile;

   // am I going to CoverYourASP?
   if ( sNew != undefined )
      Response.Redirect ( '' + sNew + '?FromShawThing' );

   // display a missing file page
   MissingFile ( sMissingFile );

The first problem I found with this is that people were linking straight to the ShowSource.asp page - this uses the QueryString to name the page to display. A typical URL would be ShowSource.asp?page=Categories. The 404 handler unfortunately stripped off the QueryString when it failed to find the file, so the user got redirected to ShowSource.asp - without the "page=Categories".

The solution was to leave a simple ShowSource.asp on my old site. This was the only page that used QueryStrings so I wasn't going against my "no duplicate code" principle. The file is shown below:


<%@ Language=JavaScript    EnableSessionState=false%>
<% Response.Redirect ( '' + Request.QueryString ( ) + '&FromShawThing' ) ; %>

So, that's the redirects taken care of - everyone who visits an old page on will end up at Now look again at the code above. Can you see the extra FromShawThing parameter I added to the URL? This is how I implemented the "welcome" text that appears at the top of the pages. If you want to see it, reload the page.

As you'll see below, I can even tell that you clicked on that link above!

The welcome text was added to the Header () function you should all be familiar with. If not, you should read my article about how I use SSI first. The new code is shown below:

// now I'm going to test if I've been redirected from
// and if so point them at the article explaining what happened!
bRefered = Request.QueryString ( "FromShawThing" ).Count;

if ( bRefered )
   Out ( '<td colspan=3 align="center"><a href="/HowIMoved.html">You have been redirected to - find out why and how!</a></td></tr><tr>' );

You can see how I set a global variable "bRefered" if there is a "FromShawThing" in the QueryString. This variable can be used in the main page content if necessary. Incidentally, I could have checked for ShawThing in the Request.ServerVariables ( "HTTP_REFERER" ), but that's a more "expensive" call, and I couldn't then have demonstrated it above!

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems

Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!

I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?

See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!

New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!