Removing trailing question mark with htaccess

前端 未结 2 1536
悲&欢浪女
悲&欢浪女 2020-12-03 20:22

Can someone help me understand this code?

# Remove trailing ?
RewriteCond %{THE_REQUEST} ? HTTP [NC] 
RewriteRule .? /%{REQUEST_URI}? [R=301,L]
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 20:48

    RewriteCond %{THE_REQUEST} ? HTTP [NC] 
    RewriteRule .? ^%{REQUEST_URI}? [R=301,L]
    

    Isn't going to work, because ? is a reserved character for regular expressions and you'd need to escape it along with the space. Try:

    RewriteCond %{THE_REQUEST} \?\ HTTP [NC] 
    RewriteRule ^/?(index\.cfm)? /? [R=301,L]
    

    Additionally, you want this rule under your # remove trailing index.cfm rule, and not at the very bottom.

提交回复
热议问题