【问题标题】:Apache restrict file access to specific extensions, and allow directory index file to work alsoApache 限制对特定扩展名的文件访问,并允许目录索引文件也可以工作
【发布时间】:2014-09-13 20:29:18
【问题描述】:

我一直在寻找解决此问题的方法,但这些建议似乎都不适用于我的问题。

我有一个运行几个虚拟站点的 apache 网络服务器,我使用 webmin 管理它们,并且我正在尝试保护 /var/www 目录,这是我正在管理的站点的根目录。我想要的是让 apache 只提供 php、html、jpg、css、js、gif 等常见文件类型。这很好用,但我的问题是我有人访问根目录http://example.com/,并且在这种情况下,apache 设置为使用 index.php,并带有 DirectoryIndex 设置。这不起作用,我得到一个 403 Forbidden 错误,如果我把完整的补丁像http://example.com/index.php 一样工作正常。

这是网站的 apache 配置:

DocumentRoot "/var/www/"
<Directory "/var/www/">
allow from all
Options +Indexes
</Directory>
<FilesMatch "\.*$">
deny from all
</FilesMatch>
<FilesMatch "\.(png|jpg|gif|css|php|html|js)$">
allow from all
</FilesMatch>

DirectoryIndex index.php

我将如何允许访问实际上未将其放入 url 时到达的 index.php?

【问题讨论】:

  • 配置更新后是否重启了apache?根目录中是否没有 htaccess 再次推翻目录索引?
  • 是的,每次我更改某些内容时,我都会重新加载 apache 并在再次测试之前清除浏览器缓存,并且根目录中没有 .htaccess 文件。

标签: php apache .htaccess indexing


【解决方案1】:

尝试将文件匹配模式更改为:

<FilesMatch "\.(png|jpg|gif|css|php|html|js)$">
allow from all
</FilesMatch>

<FilesMatch "\.(?<!png|jpg|gif|css|php|html|js)$">
deny from all
</FilesMatch>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    相关资源
    最近更新 更多