允许访问特定文件,但排除.htaccess子目录中同名文件

允许访问特定文件,但排除.htaccess子目录中同名文件,.htaccess,.htaccess,我有以下目录结构: 文件夹 示例 index.php .htaccess index.php other.php 我想拒绝访问/folder中的所有内容,但/folder/index.php除外。我可以拒绝访问所有文件,然后允许访问index.php,但这也允许访问index.php子目录中的任何index.php Order allow,deny Deny from all <FilesMatch ^index\.php$> Allow from all <

我有以下目录结构:

  • 文件夹
    • 示例
      • index.php
    • .htaccess
    • index.php
    • other.php
我想拒绝访问
/folder
中的所有内容,但
/folder/index.php
除外。我可以拒绝访问所有文件,然后允许访问
index.php
,但这也允许访问
index.php
子目录中的任何
index.php

Order allow,deny
Deny from all
<FilesMatch ^index\.php$>
    Allow from all
</FilesMatch>
命令允许,拒绝
全盘否定
通融

我如何修改
.htaccess
以仅允许访问
index.php
,它与
.htaccess
位于同一目录中?请注意,除了
/index.php和
.htaccess
之外,所有文件夹和/或文件名都可能更改。您可以使用此
mod rewrite
规则拒绝访问
/folder
中除
/index.php
以外的所有文件

Order allow,deny
Deny from all
<FilesMatch ^index\.php$>
    Allow from all
</FilesMatch>
 RewriteEngine  on
 #check if the file exists
 RewriteCond %{REQUEST_FILENAME} -f
 #check if the file is being requestsed from /folder
 RewriteCond %{REQUEST_URI} ^/folder/
 #deny access to all existant files except index.php
 RewriteRule !folder/index\.php - [L,R=403]
如果通过浏览器访问,这将返回除
/index.php
之外的所有文件的403禁止错误。 上述规则仅适用于
/文件夹
中的文件。如果要拒绝访问所有文件(包括文件和子文件夹),只需删除第一个条件
RewriteCond%{REQUEST\u FILENAME}-f