2014-10-02 114 views
1

我从/东西重定向到/某事/与设置在我的.htaccess文件:重定向到路径以“/”结尾

RewriteCond %{REQUEST_URI} !\. 
RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA] 

我想添加同样的事情页面从而结束上123.html

RewriteCond %{REQUEST_URI} [0-9]+\.html$ 
RewriteRule ^(.*[0-9]+\.html[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA] 

它没有工作......但!

RewriteCond %{REQUEST_URI} [0-9]+\.html$ 
RewriteRule ^(.*[0-9]+\.htm.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA] 

该变种完美!为什么apache不喜欢“l”?谁知道?

Apache的版本:2.4.9

回答

1

你试图不工作的规则是:

RewriteRule ^(.*[0-9]+\.html[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301,QSA] 

不工作,因为你的正则表达式是不正确的您的请求URI与.html结束,并没有什么在.html之后。因此\.html[^/]与URI不匹配,但\.htm.*[^/]确实匹配,因为最后的[^/]匹配字母l

正确的规则是:

RewriteRule ^(.*[0-9]+\.html)$ http://%{HTTP_HOST}/$1/ [L,R=301] 

PS:你也不需要使用RewriteCond