.htaccess in subdirectory 以拒绝子目录中除 index.php 之外的所有内容



以下是Web托管目录的外观:

  • public_html

    • 子目录
      • 索引.php
      • 其他东西
      • .htaccess

有没有办法使 .htaccess 文件拒绝与其位置相关的所有内容(即子目录中的所有内容),除了该目录中的索引.php文件,而不会影响位于其父目录中的任何内容?

我已经尝试了以下内容,但它也拒绝我访问/subdirectory/。 如果我做/subdirectory/index.php它似乎可以工作。

Order Deny,Allow
Deny from all
Allow from 127.0.0.1
<Files ./index.php>
Order Allow,Deny
Allow from all
</Files>

最理想的是,如果解决方案与它所在的目录结构无关——也就是说,将来我可以将所有内容移动到父目录,并且它仍然有效。

在提到的.htaccess位置尝试一下:

RewriteEngine On
RewriteRule !^(index|$) - [F]

这只允许请求在此目录中index,不会影响父目录。

最新更新