2012-03-29 88 views
17

我的主要public_html目录具有以下的.htaccess规则:如何停止子目录继承父母的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> 

的问题是,我当时有一个名为源的子目录,我想那个目录列表其中的文件(因为没有索引文件)。问题是上述父目录的htaccess规则导致目录索引中没有显示源文件(它只是列出了一个空白索引)。

我该如何解决这个问题?

THANKS

回答

19

这种变化你的.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

谢谢,这工作完美! – user1280853 2012-03-29 16:02:01

+1

你为我节省了多少解决方案。 – Naeem 2014-02-19 10:46:20

3

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

UPDATE:

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

然后,在子文件夹中的.htaccess文件,把这个单行: Options +Indexes

这是否达到预期效果?

+0

有,我有,但我不知道用来改写从父的.htaccess文件中的设置的设置。 – user1280853 2012-03-29 12:36:07

+0

我用可能的解决方案更新了答案,该解决方案可能适用于您的方案。 – 2012-03-29 12:58:31

+0

简单,快速和强大的解决方案!当然,你是一个拯救生命的人。 – 2015-03-02 08:35:56