如何限制从所有子目录查看php.ini?

时间:2016-05-12 19:52:40

标签: php apache .htaccess

我现在可以更改.htaccess文件,以防止通过网络浏览器打开php.ini和其他文件:

# Prevent .ini and other files from being open from web browser
<filesMatch "\.(htaccess|htpasswd|ini|log|sh)$">
 Order Allow,Deny
 Deny from all
</filesMatch>

但这似乎仅适用于我放置此.htaccess文件的根目录,因此如果我导航到www.mysite.com/sub/php.ini,它仍然可以打开该文件。

知道如何为所有子目录中的所有此类文件制作过滤器吗?

1 个答案:

答案 0 :(得分:1)

您可以将其添加到您的apache配置httpd.conf或您的.htaccess本身。

<Files "*.ini">
    Require all denied
</Files>

或者这也可行:

<Files "*.ini">
    Order Allow,Deny
    Deny from all
</Files>

如果您想保留目前的格式,可以这样做:

<filesMatch ".*\.(htaccess|htpasswd|ini|log|sh)$">
    Order Allow,Deny
    Deny from all
</filesMatch>