【问题标题】:.htaccess in subdirectory to deny everything in subdirectory except index.php.htaccess 在子目录中拒绝除 index.php 之外的子目录中的所有内容
【发布时间】:2019-02-15 06:16:29
【问题描述】:

这是网络托管目录的样子:

  • public_html

    • 子目录
      • index.php
      • 其他东西
      • .htaccess

有没有办法让 .htaccess 文件拒绝与其位置相关的所有内容(即子目录中的所有内容),但该目录中的 index.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


    【解决方案1】:

    在提到的.htaccess 位置试试这个:

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

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

    【讨论】:

    • 我能知道你为什么使用|$吗?
    • @Kerkouch 适用于目录/索引和目录/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2023-01-20
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    相关资源
    最近更新 更多