Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

CGI index as text

by Anonymous Monk
on Nov 24, 2004 at 06:00 UTC ( [id://410056]=perlquestion: print w/replies, xml ) Need Help??

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

I hired a coder a few years back to design a site completely in CGI. Everything worked perfectly until one day that web host went down. Now, a few years later, I am trying to get it back online.

The entire site is CGI including index.cgi. Little did I know that my current webhost doesn't allow CGI files executed outside the www directory. So now I'm sort of stuck. The main index page is a CGI file, how can I get it to load?

I believe I heard one time that you can change how things appear to load with .htaccess. Is there a way I can make ANY file load by default when my page is called from it's root domain? If this is done via .htaccess, my site says it has it so any help from there would be great.

Or am I out of luck and I need to find a new webhost?

Replies are listed 'Best First'.
Re: CGI index as text
by tachyon (Chancellor) on Nov 24, 2004 at 06:40 UTC

    It depends on their Apache setup. If you drop a .htaccess file into your webroot that looks like this:

    DirectoryIndex index.cgi AddHandler cgi-script .cgi .pl Options +ExecCGI

    Then add an index.cgi that looks like this:

    #!/usr/bin/perl print "Content-Type: text/html\n\nHello World!\n";

    and finally chmod 755 it....chmod 755 /blah/public_html/index.cgi

    You should see the famous phrase if .htaccess of the default Apache httpd.conf directives is allowed. A 500 Internal Server Error or 403 Forbidden also probably indicates it is working but you have a typo or forgot the chmod respectively. If you see your index.htm(l) instead then the .htaccess override of the DirectoryIndex is not working.

    You may also like to add:

    ErrorLog /some/path/logs/error_log CustomLog /some/path/logs/access_log common

    To your .htaccess. This gives you a private set of error logs if you don't already have them. Make sure the path exists though and is writable by Apache. It gets upset if it can't write logs.....

    cheers

    tachyon

Re: CGI index as text
by reneeb (Chaplain) on Nov 24, 2004 at 06:53 UTC
    You can do it in more than one way: The following solutions are for an Apache-webserver...
    *) change the DocumentRoot
    *) use mod_rewrite

    You can do these changes in the configfile of the apache (httpd.conf) if you have root-access or you can do this with .htaccess

    If your webhoster provides Confixx you can manage this under "tools"->"domains"!
Re: CGI index as text
by nedals (Deacon) on Nov 24, 2004 at 06:47 UTC
    If, for one reason or another, that will not work, you could 'brute force' using a blank index.html with
    <meta http-equiv="refresh" content="1;URL=/cgi-bin/index.cgi">
    as a last resort!

      This is *extremely* unlikely to work. With a GET request and this redirect you will lose the QUERY_STRING. With POST it is even worse as it will almost certainly generate a 405 Method Not Allowed as you try to POST data to an HTML page.

      cheers

      tachyon

        The OP made this statement...
        The main index page is a CGI file, how can I get it to load?

        I understood this to mean that when initially accessing the site, the index page is a cgi script that needs to be accessed. There will be 'NO' QUERY_STRING or POST. This simply redirects the normal index page to the CGI script without the use of .htaccess (I also believe the .htaccess method is a better way to do it.)

        Please explain *extremely* unlikely to work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://410056]
Approved by tachyon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-16 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found