artist has asked for the wisdom of the Perl Monks concerning the following question:

Using CGI.pm, I can redirect to a 'filenotfound.htm' file for 404 message, along with status "404 Not found". Now, instead of specifiying the file name from Perl program, I like to use whichever '404 file' specified in Apache Server's httpd.conf. How do I accomplish this? I am not using any 'Apache::' modules.

Thanks,

--Artist

Replies are listed 'Best First'.
Re: 404 to Apache
by friedo (Prior) on Oct 27, 2006 at 16:44 UTC

    If you're not running under mod_perl, then you'll need to parse your Apache's httpd.conf yourself, since server configuration information is not passed to a CGI environment. Config::ApacheFormat can probably be of use.

    If you are running under mod_perl, then you can use the dir_config method on the request object to get configuration information.

      I don't need to know the location of '404 file' specified in Apache server. I might just to need to return the header as '404 not found' and let Apache server pickup from that.
      --Artist
        It doesn't appear that will happen. You can send a '404' status through the header status CGI print $q->header(-status=>404); (which works, it does send a 404 error to the browser) but Apache seems to ignore it. As one might expect, since a 404 should normally occur before the script is called.

        You'll either have the use the Apache modules or parse the config for the standard Apache (ErrorDocument 404 /missing.html) page and return that along with the header status of 404.



        grep
        One dead unjugged rabbit fish later