【发布时间】:2016-07-20 21:46:38
【问题描述】:
是否可以允许通过
当前设置:
<FilesMatch "\.php$">
Deny from all
</FilesMatch>
<Directory /var/www/>
<Files index.php>
Allow from all
</Files>
</Direcotry>
<Directory /var/www/admin/>
<Files index.php>
Allow from all
</Files>
</Direcotry>
假设如下:
- 我们在web-root中有一个index.php,在子文件夹admin中有一个,在其他各种子文件夹中,也有一些index.php文件。
- 如果没有明确允许,则不应访问 *.php - 在这种情况下只有 /index.php 和 /admin/index.php
会发生什么:
当允许访问 webroots index.php 时,所有子文件夹中的所有 index.php 文件都可以访问。
尝试了什么:
使用 DirectoryMatch 禁止访问子文件夹中的 index.php。
<FilesMatch ".+\.php$">
Deny from all
</FilesMatch>
<Directory /var/www/>
<Files index.php>
Allow from all
</Files>
</Direcotry>
<DirectoryMatch "/var/www/(.+)/">
<Files index.php>
Deny from all
</Files>
</DirectoryMatch>
<Directory /var/www/admin/>
<Files index.php>
Allow from all
</Files>
</Direcotry>
现在,禁止访问所有子文件夹中的所有 index.php 文件 - 但仍应允许访问 /admin/ 中的 index.php。
还尝试了文件的绝对路径
<FilesMatch ".+\.php$">
Deny from all
</FilesMatch>
<Files /var/www/index.php>
Allow from all
</Files>
<Files /var/www/admin/index.php>
Allow from all
</Files>
这也不起作用。 没有 index.php 文件可以访问 - 即使是 webroot 和 admin 文件夹中的文件也无法访问。
我相信有更好的方法来解决这样的问题?
亲切的问候,
多米尼克
【问题讨论】:
-
您的设置有问题:您无法用
</FilesMatch>标签关闭打开的<Files>标签。查看文档:httpd.apache.org/docs/current/mod/core.html#filesmatch 这当然应该在您的 http 服务器错误日志文件中指出。更改设置时需要监控该文件。 -
你好 arkascha,谢谢你的提示。不幸的是,这个错误在真正的配置文件中不存在。在这里写问题时出现了这个错误。即使使用正确的打开和关闭标签,也会出现此问题
-
IIRC,那么您可以将
<FilesMatch>指令放在<Directory>标记内。您可以使用通配符为子文件夹定义另一个目录标签(例如<Directory /some/path/*>)并再次使用拒绝访问<FilesMatch>指令。可能值得一试。
标签: apache .htaccess httpd.conf