http://www.perlmonks.org?node_id=380745

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

I'm looking for options in capturing all HTTP requests to a host (or a specific directory of a host) by one script. The environment that I'm working in is Apache HTTP (version 1.3). Sometimes I'm able to use mod_perl, but for the most part I'm required to use CGI.

So far I've been able to make use of

ErrorDocument 404 /myapp/index.cgi

This works well, providing /myapp/index.cgi with all requests made to any path within the /myapp directory (such as /myapp/foo/bar).

The problem with this is that it fills up Apache's error log.

Are there other methods? If so, how does Perl get at the requested path (I've had problems with this when attempting to use mod_rewrite)?

Replies are listed 'Best First'.
Re: Ways for capturing all requests under Apache
by BUU (Prior) on Aug 06, 2004 at 22:16 UTC
    I think you want something along the lines of:
    <Directory /foo/bar> SetHandler "my_module" #SetPerlHandler ? </Directory>
      Thank you. The final snippet of .htaccess code that works for me turns out to be:

      Action my-handler /cgi-bin/index.cgi SetHandler my-handler

      And the requested path is available to the script in the PATH_INFO environment variable.

      UPDATE: For this to work, a file named index.cgi must be available in the same directory as the .htaccess file. The file may be empty or contain anything, since it is never executed. (Question: why is this file needed by Apache?)

Re: Ways for capturing all requests under Apache
by Zaxo (Archbishop) on Aug 06, 2004 at 22:08 UTC

    Are you looking for DirectoryIndex /cgi/foo.cgi in .htaccess? See the apache manual for its properties.

    After Compline,
    Zaxo

      This only sets the name of the file that Apache will look for when a path is requested without a filename. If the directory does not exist, then an error document is returned.