[Re: Perl Question?]

Jeffrey Utter utterjef@zelda.cl.msu.edu
Tue, 16 Oct 2001 15:18:27 -0400 (EDT)


On 16 Oct 2001, Matt Graham wrote:

> Edward Glowacki <glowack2@msu.edu> wrote:
> > Quoted from Jeffrey Utter on Tue, Oct 16, 2001 at 02:21:52PM -0400:
> >> 
> >>I have a perl script running on my server that takes in part of a url 
> >>as it's argument then loads the appropriate page.
> > > 
> >> Here is an example:   say I want to load  /user/Jeff/page/
> >> 
> >> well the call to the script looks like script.pl?/user/Jeff/page/
> >> This is kind of like a big wrapper to go around any other html code I
> >> happen to create so I don't have to type it over and over again.  
> >> 
> >> anyway the question is:  Is there a way I can have a perl script tell 
> >> the webserver that it had a 404 error?  so the server 404 page is 
> >> generated as a response.  
> 
> > I'm not sure the exactly, but your question prompted me to look up
> > the answer to a question I've had for a long time.
> > 
> > Question:  How do you customize the 404 page? =)
> > 
> > Answer:  Add something like this to your apache.conf (or httpd.conf
> > or whatever it is these days),
> > 
> > ErrorDocument 404 /usr/local/www/data/error404.html
> 
> Jeff:  You need to clarify what you want here.  A Perl script will not "have a
> 404 error", it will be unable to open a file for reading.  I assume you're
> taking the argument passed in from the URL and running a -r on it, so if the
> -r comes back FALSE, you should be able to use something from CGI.pl to issue
> a redirect that leads to the error document.  I had a bit of badly written
> code that did something very similar to this, but I seem to have left it at
> home.  Hmm, let's try this.  Warning, this has not been tested and may cause
> your Apache to explode:
> 
> #!/usr/bin/perl -w
> use CGI qw/:standard/;
> 
> $query = new CGI;
> #initialization, etcetera, do NOT print a header or anything until...
> $file_to_get = $query->param;  # you have a name for this param?
> if(not -r $file_to_get){
>     print $query->redirect('http://myserver.org/error404.html');
>     exit 0;
>     }
> # the script you had before continues here.

That's close to what I need only I don't want to display my own error page
I want the server to do it. and log it and do everything it normaly would
had the file been linked to directly.  

right now I'm looking into a sub function that sends the page header for a
404.  

sub killme{
   print "Status: 404\n\n";
   die 404;
}

this kills the script and gives a document contained no data.. but it's
closer to what I need..

Jeff