问题
So, I finally released my first perl module on CPAN (http://search.cpan.org/~insaner/CGI-apacheSSI/lib/CGI/apacheSSI.pm), which allows your perl scripts to parse SSI files like apache's mod_include
would. And as I work through the first round of bug fixes, (having followed @brian d foy's advice of "Upload early & often -- You don’t have to be perfect, or even good" -- very good and encouraging advice by the way, especially for first-timers like me) there is one problem I am not sure how to best tackle.
I am calling a script, which uses CGI::apacheSSI
to parse a file which has a few include calls itself, one of which is a virtual include
call to a file which resolves to another cgi script. The include calls to the non-script file work fine, and the ENV variables that were set in the script are used fine in the parsed file, as expected. However, the original code I forked the module from was doing a URI::get
to get the text to be included in such instances. Obviously, this would not allow me to do SSI includes on that text, since that would have been all done by apache before sending it to my module, ignoring the ENV variables I needed set.
For clarification, imagine an instance that is something like this:
A perl script /cgi-bin/script.cgi calls
CGI::apacheSSI
, setting MYVAR="myval", and then "include()
"s the file /path/myfile.shtmlin the file /path/myfile.shtml there is an echo of MYVAR and two
include virtual
SSI calls, one to /path/more/myfile2.shtml and another to /path/more/myfile3.shtml.in /path/more/myfile2.shtml there is an echo of MYVAR
/path/more/myfile3.shtml is rewritten by a mod_rewrite rule to /cgi-bin/myscript2.cgi which prints $ENV{MYVAR}
If I only use apache, I can have a file /topfile.shtml which sets MYVAR="myval" and does a virtual include
of /path/myfile.shtml and I will get 3 instances of "myval" printed.. I want this same result if I use the module, but as it stands, I only get the first 2.
So here is my question: how can I either
- a) get apache's current configuration values such that I can know with some level of reliability (in consideration of
mod_rewrite
rules or variables set in .htaccess files) what an included file will resolve to, so that if it is a script, I can simply call it myself with backticks and therefore have it receive my ENV. In other words, is there a CPAN module that processes apache configurations (server config files and .htaccess files) such that I can send it a path and it will tell me what it resolves to after rewrite rules are applied?
or
- b) make an external (or internal) call (using get() for example) somehow sending over the variables (hopefully the entire ENV) I want apache to use when generating the resulting html?
I think option b) is the least optimal option, but would do fine for now.
Hopefully this all makes sense and someone can help me out here.
来源:https://stackoverflow.com/questions/25627164/figure-out-apache-mod-rewrite-resolutions-in-perl-cgi-and-passing-variable-value