PERL: Intelligent redirect

Roy Tennant rtennant at library.berkeley.edu
Tue Mar 10 11:46:52 EST 1998


I am trying to use a PERL program to handle 404 Not Found errors and I'm
having difficult making it work the way I want. For example, if someone
enters:

http://sunsite.berkeley.edu/govdata/info/

and the URL is actually

http://sunsite.Berkeley.EDU/GovData/info/

the user will get bounced to a program that will replace "govdata" with
"GovData" and send the user on their way to the real site. That part seems
to work fine. My problem comes in when there is something wrong with the
rest of the URL. Rather than being sent to my static page for "when all
else fails", they get the cryptic server-produced "404 Not Found" error,
which is unacceptable. 

I have tried to catch the fact that I've already been bounced once by
seeing if the HTTP_REFERER environment variable has the program name, but
that doesn't work. Any other ideas out there in Web4Lib land? Go
easy on me, I'm not a real programmer, I only play one on the Web. Thanks,
Roy Tennant

#!/usr/local/bin/perl

if ($ENV{'HTTP_REFERER'} =~ /notfound/) {
  print "Location: /errors/notfound.html\n\n";
} elsif ($ENV{'QUERY_STRING'} =~ /govdata/) {
  @temp = split(/=/,$ENV{'QUERY_STRING'});
  $_ = $temp[1];
  s/govdata/GovData/;
  print "Location: $_\n\n";
} else {
  print "Location: /errors/notfound.html\n\n";

}





More information about the Web4lib mailing list