我的主要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规则导致源中没有文件显示在目录索引中(它只列出一个空索引)。
我该如何解决这个问题?
感谢
答案 0 :(得分:21)
用此更改你的.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>
答案 1 :(得分:3)
这可能是显而易见的,您已经尝试过了 - 但是您是否在感兴趣的子文件夹中创建了一个.htaccess文件?此文件中的任何设置都将覆盖根文件夹中的等效设置。
更新:
对于根.htaccess文件,而不是
IndexIgnore */*
......试试
Options -Indexes
然后,在子文件夹的.htaccess文件中,放置以下单行:
Options +Indexes
这是否达到了预期的效果?