2015-02-24 69 views
1

请求我的网站像/ profile,/ profile /,/ market(有或没有最终斜杠)和/ api /任何资源都很好,但是当我尝试请求/ api斜杠)我得到301永久移动和重定向到/ api /?_ url = api/api。/profile和/ api之间的区别Apache以及如何解决此重定向?Apache的/ api请求上的奇怪行为

我的.htaccess看起来是这样的:

RewriteEngine on 
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpeg|jpg|svg)$ 
RewriteRule ^(.*)$ controller.php?_url=$1 [QSA,L] 

我使用Apache 2.2.27

回答

1

差异是最有可能/api/是一个目录,mod_dir被添加尾随斜线后,上述规则是在mod_rewrite模块中运行。您可以通过以下代码来控制此行为:

# turn off auto-trailing slash after a directory 
DirectorySlash off 
RewriteEngine on 

# add a trailing slash to directories 
RewriteCond %{DOCUMENT_ROOT}/$1 -d 
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302,NE]  

RewriteCond %{REQUEST_URI} !\.(css|js|png|jpeg|jpg|svg)$ [NC] 
RewriteRule ^(.*)$ controller.php?_url=$1 [QSA,L]