详解调试Apache的mod_rewrite模块

在旧的Apache的httpd.conf里面是有这样的参数的:

1 RewriteLog "/myfolder/mylogfile.log"
2 RewriteLogLevel 3

但是在新版本的Apache中,已经取消了RewriteLog这个参数,如果你加上这个参数只会使你的Apache无法启动!新版本的Apache已经把Rewrite模块的日志也写到了Apache的error.log中,只需要我们制定一下输出的log的级别和trace的深度就好了,例如

1 LogLevel alert rewrite:trace3

LogLevel的级别和深度选择如下表:

Level Description Example
emerg Emergencies – system is unusable. “Child cannot open lock file. Exiting”
alert Action must be taken immediately. “getpwuid: couldn’t determine user name from uid”
crit Critical Conditions. “socket: Failed to get a socket, exiting child”
error Error conditions. “Premature end of script headers”
warn Warning conditions. “child process 1234 did not exit, sending another SIGHUP”
notice Normal but significant condition. “httpd: caught SIGBUS, attempting to dump core in …”
info Informational. “Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)…”
debug Debug-level messages “Opening config file …”
trace1 Trace messages “proxy: FTP: control connection complete”
trace2 Trace messages “proxy: CONNECT: sending the CONNECT request to the remote proxy”
trace3 Trace messages “openssl: Handshake: start”
trace4 Trace messages “read from buffered SSL brigade, mode 0, 17 bytes”
trace5 Trace messages “map lookup FAILED: map=rewritemap key=keyname”
trace6 Trace messages “cache lookup FAILED, forcing new map lookup”
trace7 Trace messages, dumping large amounts of data “| 0000: 02 23 44 30 13 40 ac 34 df 3d bf 9a 19 49 39 15 |”
trace8 Trace messages, dumping large amounts of data “| 0000: 02 23 44 30 13 40 ac 34 df 3d bf 9a 19 49 39 15 |”

因此我们假如需要调试某个虚拟主机的伪静态的话,我们可以在给虚拟主机的<VirtualHost>配置项或者.htaccess里面加入如下的一段配置:

1 <IfModule mod_rewrite.c>
2 LogLevel debug rewrite:trace3
3 </IfModule>

然后访问一下,error.log里面就会有具体的信息了,可以看到你提交的URL被映射到了哪个文件,进行有针对性的调整。

附官方说明文档:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging
再附一个.htaccess调试网址:
http://martinmelin.se/rewrite-rule-tester/ 

除非注明, 风波竹林 文章均为原创,转载请以链接形式标明本文地址
本文地址: https://blog.fbzl.org/详解调试apache的mod_rewrite模块/

发表评论

电子邮件地址不会被公开。