我有一个Apache实例但是没有PHP (我发现的几乎所有SO答案都是特定于PHP的)。事实上,它主要服务于静态内容。
我正在处理一些mod_rewrite
重定向,我想知道所有环境变量的确切值。
这些页面列出了Apache的可用env变量和示例值
然而我希望看到来自我的请求的确切值,以便于处理我的重写规则。
获取所有Apache环境值的最简单方法是什么?(不安装PHP)。
作为穷人的调试,我知道我可以通过定义一些像这样的重写来逐个获取值
RewriteRule ^/test.htm http://localhost/test2.htm?SERVER_NAME=%{SERVER_NAME} [R,L,NC]
然后点击http://localhost/test.htm
并观察重定向,但这不是一个非常好的解决方案。
有没有更好的方法来了解所有环境,而不是像PHP这样的特定语言?
答案 0 :(得分:1)
您可以使用Perl获取所有Apache环境变量的值。标准的Apache发行版仍然捆绑了旧的printenv.pl
CGI脚本。这是我的(Windows上的Apache / 2.4):
#!D:/programs/perl/bin/perl.exe
#
# To permit this cgi, replace # on the first line above with the
# appropriate #!/path/to/perl shebang, and on Unix / Linux also
# set this script executable with chmod 755.
#
# ***** !!! WARNING !!! *****
# This script echoes the server environment variables and therefore
# leaks information - so NEVER use it in a live server environment!
# It is provided only for testing purpose.
# Also note that it is subject to cross site scripting attacks on
# MS IE and any other browser which fails to honor RFC2616.
##
## printenv -- demo CGI program which just prints its environment
##
use strict;
use warnings;
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach my $var (sort(keys(%ENV))) {
my $val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
当然:
使用程序的其他人,你运气不好。我不知道有任何内置Apache模块报告ENV变量(甚至不是mod_info
)。