首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何停止子目录继承父目录的htaccess规则

如何停止子目录继承父目录的htaccess规则
EN

Stack Overflow用户
提问于 2012-03-29 20:07:01
回答 2查看 28.5K关注 0票数 25

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

代码语言:javascript
复制
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规则导致源目录中的文件不会显示在目录索引中(它只列出了一个空索引)。

我该如何解决这个问题呢?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-29 20:58:56

使用以下命令更改您的.htaccess:

代码语言:javascript
复制
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>
票数 22
EN

Stack Overflow用户

发布于 2012-03-29 20:29:58

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

更新:

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

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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9924987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档