我使用以下规则从所有网址中删除尾随斜杠
#remove /
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
规则对于主页/
工作正常通过
ERR_TOO_MANY_REDIRECTS
我已启用mod_ rewrite日志来跟踪规则
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (2) init rewrite engine with requested uri /
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (3) applying pattern '^(.*)$' to uri '/'
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (3) applying pattern '^(.*)\\/(\\?.*)?$' to uri '/'
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (2) rewrite '/' -> ''
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (2) explicitly forcing redirect with http://www.mywebpage.com/
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (1) escaping http://www.mywebpage.com/ for redirect
10.64.159.12 - - [14/Feb/2018:12:04:16 +0400] [www.mywebpage.com/sid#7effdd821860][rid#7eff00068100/initial] (1) redirect to http://www.mywebpage.com/ [REDIRECT/301]
任何想法为什么它不适用于主页url并适用于所有其他页面url
答案 0 :(得分:3)
要删除尾随斜杠,请将此规则作为您的第一条规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=301,L]