- A+
所属分类:神兵利刃
大家都知道Apache里面的Rewrite规则是一件很蛋疼的事情,有时候只是想做一个伪静态而已,不想去研究那些复杂的规则,可官方给的规则又常常出错,出了问题我们就要调试一下,看看提交的参数被映射到了哪里。在网上搜了一下全都是说在apache里面加RewriteLog,而且中文的介绍完全没有。
在旧的Apache的httpd.conf里面是有这样的参数的:
RewriteLog "/myfolder/mylogfile.log" RewriteLogLevel 3
但是在新版本的Apache中,已经取消了RewriteLog这个参数,如果你加上这个参数只会使你的Apache无法启动!新版本的Apache已经把Rewrite模块的日志也写到了Apache的error.log中,只需要我们制定一下输出的log的级别和trace的深度就好了,例如
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里面加入如下的一段配置:
<IfModule mod_rewrite.c> LogLevel debug rewrite:trace3 </IfModule>
然后访问一下,error.log里面就会有具体的信息了,可以看到你提交的URL被映射到了哪个文件,进行有针对性的调整。
附官方说明文档:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging
再附一个.htaccess调试网址:
http://martinmelin.se/rewrite-rule-tester/
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫