2016-01-03 20 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