in reply to CGI as an Inline Path

You'll find that $ENV{'PATH_INFO'} holds what you're looking for.

Replies are listed 'Best First'.
Re: Re: CGI as an Inline Path
by seattlejohn (Deacon) on Mar 15, 2002 at 07:45 UTC
    ++dws, and note that contrary to comments below, mod_rewrite or other trickery is not necessary.

    It sounds like you've already figured out how to get the script itself running even though it's not in the CGI directory -- but if not, Apache's ScriptAlias or ExecCGI directives should do the job. And of course Apache respects the script's shebang line even on Windows, so you don't need to worry about having a .cgi or .pl extension or anything like that.

    I couldn't tell you whether this would work with IIS, though.

      I couldn't tell you whether this would work with IIS, though.

      IIS does have some peculiarities in it's handling of PATH_INFO that you should be aware of, but there's a knowledge base article on the subject that may be of interest.

      Update: If you use CGI.pm's path_info instead of $ENV{'PATH_INFO'}, it has a hack that'll return what you expect regardless of how IIS is configured.

      sub path_info { # .... # hack to fix broken path info in IIS $self->{'.path_info'} =~ s/^\Q$ENV{'SCRIPT_NAME'}\E// if $IIS; }

          --k.


      Thank you - and yes, getting it to use an arbitrary CGI was an easy task without the handler code. My only issue was getting the darned query portion - which (*DOH!* thanks dws!! I really should sleep more *sigh* ) I was reminded from earlier.

      As fas as IIS goes - yes it is easy to set up a handler in it as well (just add one in 'site properties | ISAPI Filters').

      To do a simple passthrough on an Unix/Apache server I simply (as you suggested) put in a script alias for my cgi app in my appache configration file. ie

      ScriptAlias /MyCGI/ "/usr/local/www/cgi-bin/sitescript"



      *G*
Re: Re: CGI as an Inline Path
by Juerd (Abbot) on Mar 15, 2002 at 08:00 UTC

    You'll find that $ENV{'PATH_INFO'} holds what you're looking for.

    And %ENV has more interesting information, so dumping it is not a bad idea:

    #!/usr/bin/perl -w use Data::Dumper; print "\n"; # The shortest CGI header possible, # the server will assume text/plain. print Dumper \%ENV;
    Or, without Data::Dumper:
    #!/usr/bin/perl -w print map "\n$_ => $ENV{$_}", keys %ENV;

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk