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

Is it possible to run cgi-scripts directly from index.html? E.g. when a client makes a request for index.html is it then possible to run cgi-scipts directly as a response to their request. Thank you for any help.

Replies are listed 'Best First'.
Re: Fundamental cgi-question
by chromatic (Archbishop) on Feb 28, 2006 at 20:26 UTC

    Depending on the webserver, you can do anything in response to a request. You could make it run all .html files through an Apache module (mod_cgi, mod_perl, mod_php, whatever) or set up a custom 404 handler and not put an index.html in that directory or send all requests to the parent part of the URL to a custom handler, for example.

Re: Fundamental cgi-question
by ikegami (Patriarch) on Feb 28, 2006 at 21:07 UTC

    I presume you more interested in making the default file executable, rather than index.html specifically.

    When no file is specified (as in http://www.example.com/ and http://www.example.com/dir/), the web server looks for a list of files. Usually that list starts with index.html. If you use the following command (Apache's syntax), the web server will use index.cgi as the default if index.cgi is not found.

    # Globally, in <VirtualHost>, in <Directory> or in .htaccess DirectoryIndex index.html index.cgi

    For example, if you have that line in your <VirtualHost>, requesting http://www.example.com/ would be the same as http://www.example.com/index.cgi.

Re: Fundamental cgi-question
by gman (Friar) on Feb 28, 2006 at 20:12 UTC
    Probably not the best solution, but I have used a redirect.
    <meta http-equiv="REFRESH" content="0;url=/cgi-bin/index.pl">

    A server re-write would probably be the best solution.
    Not sure I understood the question correctly.

Re: Fundamental cgi-question
by mda2 (Hermit) on Mar 01, 2006 at 02:34 UTC
    Iīm supose the best is a mod_perl handler to do it... see the "First Mystery" from modperl ;)

    Basically you assing a package to work with <location> tag of Apache.

    Others options are available... redirects (I donīt like it) and SSI (Server Side Includes).

    --
    Marco Antonio
    Rio-PM

Re: Fundamental cgi-question
by Anonymous Monk on Feb 28, 2006 at 23:01 UTC
    Here is a simple index.html example that redirects a user's request for index.html to your script:
    <html> <head> <script language="javascript"> <!-- location.replace('http://server.name/your/script'); // --> </script> </head> <body>This site requires javascript.</body> </html>