我有一个这样的文件夹结构:
subdir
|_ subsubdir
|_ index.php
|_ other_stuff.php
|_ images
|_ pic.jpg
.htaccess
config.ini
index.php
Run Code Online (Sandbox Code Playgroud)
.htaccess 文件的内容:
Options +FollowSymLinks -MultiViews -Indexes
Order Deny,Allow
<FilesMatch "(\.ini$)|(\.php$)|(^\.)">
Deny from all
</FilesMatch>
<Files index.php>
Allow from all
</Files>
Run Code Online (Sandbox Code Playgroud)
我的目标是让用户无法查看 subdir/subsubdir/index.php(以及所有其他 *.php 文件,无论在哪里,但这已经有效),但允许他们查看根目录中的 index.php。
目前,用户显然仍能够看到子目录/ subsubdir / index.php的,因为一个名为“的index.php”中的所有文件都是允许的,但我不知道如何让只是一个在根目录下,并拒绝所有其他人。我尝试过不同的事情,但最终要么完全否认,要么全部接受。
我觉得这应该是一项非常简单的任务,但我就是想不通。
我尝试过的事情:
<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>
Run Code Online (Sandbox Code Playgroud)