启用DirectorySlash而不显示查询

时间:2011-11-11 20:37:59

标签: apache .htaccess

如果我的网站根目录中的.htaccess中有此代码:

RewriteCond %{REQUEST_URI} ^/foo/bar/
RewriteRule ^foo/bar(.*)$ http://example.org/foo/?file=$1 [P,QSA]

并拥有此文件结构:

foo
 +-- index.php
 +-- bar
      +-- qaz
           +-- file.txt

我请求页面http://example.org/foo/bar/qaz/它将在服务器上重定向到http://example.org/foo/?file=/qaz/。 但是,如果我请求网页http://example.org/foo/bar/qaz,它会重定向到http://example.org/foo/?file=/qaz,但会在浏览器中显示http://example.org/foo/bar/qaz/?file=/qaz

如何启用DirectorySlash,但仍然隐藏用户的查询?

1 个答案:

答案 0 :(得分:0)

如果目录'/ foo / bar / qaz'存在,则DirectorySlash仅执行此操作。

DirectorySlash不尊重rewriteBase。您可以将其禁用并自行完成:

RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*[^/])$ $1/ [R,L]
相关问题