【发布时间】:2015-05-08 14:23:39
【问题描述】:
我有一个这样的文件夹结构:
subdir
|_ subsubdir
|_ index.php
|_ other_stuff.php
|_ images
|_ pic.jpg
.htaccess
config.ini
index.php
.htacces 文件的内容:
Options +FollowSymLinks -MultiViews -Indexes
Order Deny,Allow
<FilesMatch "(\.ini$)|(\.php$)|(^\.)">
Deny from all
</FilesMatch>
<Files index.php>
Allow from all
</Files>
我的目标是阻止用户查看 subdir/subsubdir/index.php(以及所有其他 *.php 文件,无论在哪里,但这已经有效)但允许他们查看索引.php 在根目录中。
目前,用户显然仍然能够看到 subdir/subsubdir/index.php,因为所有名为“index.php”的文件都是允许的,但我不知道如何允许 just根目录中的一个并拒绝所有其他。我尝试过不同的事情,但要么完全拒绝,要么全部允许。
我觉得这应该是一件很容易的事,但我就是想不通。
我尝试过的事情:
<FilesMatch "\.\/index\.php">
Allow from all
</FilesMatch>
---
<FilesMatch "^index\.php$">
Allow from all
</FilesMatch>
---
<Files ./index.php>
Allow from all
</Files>
---
<Files /index.php>
Allow from all
</Files>
【问题讨论】:
标签: php regex apache .htaccess webserver