2016-01-03 21 views
2

工作,在我的Web服務器我有一個htaccess文件看起來像這樣:htaccess的不正常

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA] 

所以我WebServer的所有呼叫將被重定向到index.php文件在我的根目錄下有一個路徑參數其中包含請求的文件。現在看看這兩個電話:

domain.com/test/blub.php  works -> path = test/blub.php 
domain.com/test/    does not work -> path should be test 

我怎樣才能實現第二個電話也有效?

回答

2

從規則中刪除此條件:

RewriteCond %{REQUEST_FILENAME} !-d 

由於這是跳過此規則的所有真正的目錄。

使用您的規則爲:

DirectorySlash Off 
RewriteEngine on 

RewriteCond %{DOCUMENT_ROOT}/$1 -d 
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,NE] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)/?$ /index.php?path=$1 [NC,L,QSA] 
+0

謝謝你這一點。工作非常好。但是現在路徑參數在url中顯示。我能以某種方式切斷它嗎? – Cilenco

+0

現在,如果我調用domain.com/test,它不會被重定向到index.php文件 – Cilenco

+0

對不起,您是對的。我的PHP腳本中有一個錯誤:/抱歉。 – Cilenco