重写自定义日志中的 URL

发布于 2024-12-29 17:34:02 字数 540 浏览 4 评论 0原文

我在 http.conf 中定义了一个重写 URL,以将参数附加到请求 URL。在自定义日志输出中,我没有看到修改后的请求 URL。当我查看原因时,我在一个论坛中发现 mod_rewrite 仅影响通过 HTTP 调用的访问,不会影响服务器内部的文件操作。这是真的吗?有没有办法在 Apache 日志中仅记录修改后的重写 URL?非常感谢您的帮助。

我尝试访问的示例 URL 是 http://www.abc.com/pixel.gif?on=test ,在输出中我想要类似 /pixel.gif?type =修改&on=测试

RewriteCond %{HTTP_HOST} www\.abc\.com
RewriteRule ^/(.*)$    /$1?type=modified       [QSA,L]
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

I have defined a rewrite URL in http.conf to append a parameter to the request URL. In the Custom Log output I am not seeing the modified request URL. When I looked at the cause I found in one of the forums that mod_rewrite only affects accesses invoked via HTTP and does not affect file operations inside the server. Is that true and is there any way to log only the modified rewrite URL in the Apache logs? Your help is much appreciated.

The sample URL I am trying to access is http://www.abc.com/pixel.gif?on=test and in the output I want something like /pixel.gif?type=modified&on=test.

RewriteCond %{HTTP_HOST} www\.abc\.com
RewriteRule ^/(.*)$    /$1?type=modified       [QSA,L]
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2025-01-05 17:34:02

如果您打开RewriteLog<,就有一种方法可以记录与重写相关的事情/a> 指令。

基本上,您可以将其添加到您的 .htaccess 文件(并且日志路径可能会有所不同)

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

但请注意,RewriteLogLevel 确实会减慢您的开发或生产服务器的速度。您可能想使用更小的数字...而不是 5。当您检查完 RewriteRule 后...您很可能想要注释掉(或删除)RewriteLog/RewriteLogLevel线。

希望对您的调试有所帮助!

There is a way to log rewrite-related things if you turn on the RewriteLog directive.

Basically, you would be adding this to your .htaccess file (and the log path may vary):

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

But note, that RewriteLogLevel can really slow down your development or production server. You might want to use a smaller number... instead of 5. And when you are done checking your RewriteRules... you will most likely want to comment out (or delete,) the RewriteLog/RewriteLogLevel lines.

Hope that helps with your debugging!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文