2012-03-29 87 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