【问题标题】:Page 403 Forbidden for root directory for Deny from all in .htaccess.htaccess 中的所有拒绝的根目录页 403 被禁止
【发布时间】:2023-01-30 00:05:17
【问题描述】:

我在根目录中有下一个.htaccess

RewriteEngine on
RewriteRule ^$ index.php [L]
Order Deny,Allow
Deny from all
<Files index.php>
Allow from all
</Files>

并为 www.example.com 而不是 www.example.com/index.php 获取 Page 403 Forbidden。

网址 www.example.com/index.php 可用。

关闭对根目录中所有文件的访问。这些文件由脚本生成,文件名未知。

如何解决?

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting friendly-url


    【解决方案1】:
    <Files index.php>
    Allow from all
    </Files>
    

    请尝试以下操作:

    <FilesMatch "(index.php)?">
    Allow from all
    </FilesMatch>
    

    (尽管我假设您使用的是 Apache 2.4,因此您应该使用相应的 Require 指令而不是 OrderDenyAllow。)

    或者,将所有现有指令替换为以下内容:

    DirectoryIndex index.php
    
    RewriteEngine On
    RewriteRule !^(index.php)?$ - [F]
    

    这允许访问example.com/example.com/index.php。要阻止对 index.php 的直接访问,请尝试以下操作:

    RewriteRule ^[^/]+$ - [F]
    

    mod_dir(即“DirectoryIndex”)在 mod_rewrite 之后处理。


    RewriteRule ^$ index.php [L]
    

    这条规则是多余的,应该由DirectoryIndex 处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      相关资源
      最近更新 更多