【问题标题】:I want "File does not exist" errors to be ignored or not logged我希望忽略或不记录“文件不存在”错误
【发布时间】:2023-03-12 14:15:02
【问题描述】:

[2011 年 11 月 19 日星期六 13:17:04] [错误] [客户端 1.1.1.32] 文件确实 不存在:/var/www/vhosts/x.com/httpdocs/scores.asp

[2011 年 11 月 19 日星期六 13:17:54] [错误] [客户端 1.1.1.32] 文件没有 不存在:/var/www/vhosts/x.com/httpdocs/reqewrqwe.awwe

解决了,谢谢

【问题讨论】:

标签: php flash apache file logging


【解决方案1】:

创建一个RewriteRule 并返回一个空文件以响应您要从日志中删除的 URL:

RewriteRule scores\.asp$ - [L]

如果您没有任何 URL 模式并且您想阻止所有不存在的文件,请添加 RewriteCond

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]

或者只是使用更新的 apache:

FallbackResource /index.php

然后index.php 给出 404 状态响应:

<?php
header("Status: 404 Not Found", 1, 404);

index.php 文件必须存在,否则(对于RewriteRule)这将造成无限循环。

或者,这可能会起作用(并且不需要index.php 文件):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ - [R=404,L]

见:Apache2: how to avoid logging certain missing files into error.log

【讨论】:

  • +1 或者,如果这会导致 Flash 应用出现问题,请改写为 scores.php 并让该文件发出 404 标头
  • 对不起,我意识到我没有提供足够的细节。我只是编辑第一条消息。请检查。
  • @öksürdüm:使用您拥有的替代选项扩展答案。
  • 我现在收到以下错误:“由于可能的配置错误,请求超出了 10 个内部重定向的限制。”
  • 使用FallbackResource代替(我的错),使用index.php以及RewriteRule,我会更新答案。
猜你喜欢
  • 2021-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
  • 2011-09-22
相关资源
最近更新 更多