防止使用根 .htaccess 从 Web 访问error_log


Prevent error_log from being accessible from the web using root .htaccess

我正在共享的Web托管服务上托管我的PHP站点。我需要防止通过 HTTP 请求从公共网络访问error_log文件。

我找到的当前解决方案是将以下行添加到必须放置在error_log文件所在的每个目录中的.htaccess文件中:

<files error_log>
   order allow,deny
   deny from all
</files>

它有效,但我很好奇是否有解决方案可以从根目录中的.htaccess执行此操作?

尝试:

RewriteEngine On
RewriteRule (^|/)error_log$ - [L,R=404]

或者,如果您更喜欢 403 禁止响应而不是未找到 404,请将标志替换为 [L,F]