Php Mod Rewrite如何与日志交互

Php Mod Rewrite如何与日志交互,php,apache,cakephp,mod-rewrite,logging,Php,Apache,Cakephp,Mod Rewrite,Logging,我使用的是CakePHP,我不理解mod_重写如何影响自定义日志 在.htaccess中: RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,NE] (index.php是CakePHP开始路由请求的地方) 然后在/etc/apache2/apache2.conf中: LogFormat "%U %q" custom CustomLog "/var/log/apache/custom.log" custom 但是对于请求/foo?bar=1,我明

我使用的是CakePHP,我不理解mod_重写如何影响自定义日志

.htaccess
中:

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,NE]
(index.php是CakePHP开始路由请求的地方)

然后在
/etc/apache2/apache2.conf
中:

  LogFormat "%U %q" custom

  CustomLog "/var/log/apache/custom.log" custom
但是对于请求/foo?bar=1,我明白了

/foo ?url=foo&bar=1
我不明白发生了什么事


似乎日志发生在使用
%U
重写之前,但发生在使用
%q
重写之后。这是预期的行为吗?我能换一下吗?(我的日志大小受到严格限制,不希望将每个路径记录两次。)

我不确定Apache在这里做什么,但我可以让CakePHP在根本不使用查询字符串的情况下工作:

RewriteRule ^(.*)$ index.php [QSA,L,NE,E=URL:$1]
然后在
index.php
中:

$_GET['url'] = substr(getenv('REDIRECT_URL'), 1);

无论如何,这似乎比普通的CakePHP方式要简单得多。

这不是查看mod_rewrite正在做什么的方式;你需要看看重写过程中发生了什么。您需要启用“重写日志”,以便准确查看其中发生的情况:

代码是:

RewriteLog "/usr/local/var/apache/logs/rewrite.log"

考虑到已启用重写模块,您需要重新启动apache。这将帮助您进行调试。此外,您必须将其放入虚拟主机条目中

很有趣。我认为这是Apache中值得报告的一个bug。从某种意义上讲,它的行为是这样的,但是的,我仍然认为它并不是为了这样工作。我不想知道mod_rewrite正在做什么。我正在尝试获取不包含重复数据的访问日志。(由于日志的大小限制。)