开发者

Can I log a single mod-rewrite rule when it is executed?

开发者 https://www.devze.com 2023-03-01 13:18 出处:网络
I would like to be able to log when a RewriteRule is executed. For example, say I have something like:

I would like to be able to log when a RewriteRule is executed. For example, say I have something like:

Re开发者_JS百科writeCond  %{QUERY_STRING} do=Action [NC]
RewriteRule ^/app/(.*)$  ${server:master}/code/base/path/App.php?$1 [P,L]

RewriteRule ^(.*)$  ${server:cache}/other/path/App.php$1 [P,L]

I would like to log the request urls that get rewritten by Rule 1 (on the master server).

Any idea on how to achieve this?

Thanks a huge lot!


You can use the [E] flag to set an environment variable. Then, in your log configuration on the server check for the same environment variable.

So, if you have the following RewriteRule:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/newurl/
RewriteRule (.*) /newurl/$1 [R,E=rewrite:true]

You can setup a log accordingly:

CustomLog logs/rewrite-check.log common env=rewrite

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消