使用Apache和一个prgtypes的重写映射。 我的地图看起来像:
#!/usr/bin/perl $| = 1; # Turn off buffering while (<STDIN>) { print "someothersite.com"; }
在httpd.conf中声明的重写规则是:
RewriteMap app_map prg:/file/path/test.pl RewriteRule (\/[\w]+)(\/[^\#\s]+)?$ http://${app_map:$1}$2 [P,L]
日志文件显示:
init rewrite engine with requested uri /a/testlink.html applying pattern '(\/[\w]+)(\/[^\#\s]+)?$' to uri '/a/testlink.html'
看起来像test.pl从来没有把控制权交给Apache,当地图成功find我期望在日志文件中看到这个输出:
map lookup OK: map=app_map key=/a -> val=someothersite.com
为什么我的地图不能将控制权返回给Apache?
我得到它与以下工作:
#!/usr/bin/perl # ## disable buffered I/O which would lead ## to deadloops for the Apache server $| = 1; # ## read URLs one per line from stdin while (<>) { my $line = $_; if ($line eq "input_from_apache\n"){ print "my_desired_output\n"; } else{ print "\n"; } }
尽我所能,换行符是我错过的。 对于任何想要debuggingRewriteMap脚本的人,我build议:
确保你有:
RewriteEngine On
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 9
在你的httpd.conf中,你可以看到mod_rewrite在做什么
编写你的脚本,然后启动它(即./my_script.pl
),并input一些input,以确保你得到你所期望的。 这就是我意识到我需要的\n
的
你有没有尝试让你的Perl脚本返回正确的格式? 它期望一个键/值对,即:
someval someothersite.com
这可能会纠正你的问题。 如果没有,你可以尝试使用一个txt文件来模拟你的Perl脚本返回的内容,来validationRewriteMap
是否正常工作。