【问题标题】:How to stop sub directory inheriting parent's htaccess rules如何停止子目录继承父级的 htaccess 规则
【发布时间】:2012-04-13 01:50:42
【问题描述】:

我的主要 public_html 目录有以下 .htaccess 规则:

Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>

问题是,然后我有一个名为 source 的子目录,我希望该目录仅列出其中的文件(因为没有索引文件)。问题是上述父目录的 htaccess 规则导致目录索引中没有显示源文件(它只是列出了一个空白索引)。

我该如何解决这个问题?

谢谢

【问题讨论】:

    标签: apache .htaccess inheritance


    【解决方案1】:

    用这个改变你的 .htaccess:

    Options +FollowSymLinks
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # if request is not for the /sub-dir/
    RewriteCond %{REQUEST_URI} !^/sub-dir/ [NC]
    # otherwise forward it to index.php
    RewriteRule . index.php
    </IfModule>
    

    【讨论】:

    • 你为我节省了多少时间。
    【解决方案2】:

    这可能很明显,您已经尝试过了 - 但是您是否在感兴趣的子文件夹中创建了一个 .htaccess 文件?此文件中的任何设置都将覆盖根文件夹中的等效设置。

    更新:

    对于根 .htaccess 文件,而不是 IndexIgnore */* ... 尝试 Options -Indexes

    然后,在子文件夹的 .htaccess 文件中,放置这一行: Options +Indexes

    这样能达到预期的效果吗?

    【讨论】:

    • 是的,我有,但我不知道使用哪些设置来覆盖父 .htaccess 文件中的设置。
    • 我用可能适用于您的场景的可能解决方案更新了答案。
    • 简单、快速、强大的解决方案!!毫无疑问,你是救生员。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 2017-10-28
    • 2019-01-27
    相关资源
    最近更新 更多