开发者

htaccess Rewrite rule appending query string parameters

开发者 https://www.devze.com 2023-04-12 18:02 出处:网络
I am trying to write a rewrite rule for below URLs: redirect www.domain.com/mbc-ex to www.domain.com www.domain.com/mbc-ex?abcd=123to www.domain.com

I am trying to write a rewrite rule for below URLs: redirect

  • www.domain.com/mbc-ex to www.domain.com
  • www.domain.com/mbc-ex?abcd=123 to www.domain.com

Basically, I do not want to have any query string parameters after redirection. Here is the rule I tried

^/mbc-ex\?(.*)$  http://www.domain.com [NC,L,U]

the above rule still appends开发者_如何学JAVA the query string parameters

^/mbc-ex$ http://www.domain.com [NC,L,U]

this one works as expected


It would appear that your regex is not matching at all.

^/mbc-ex\?(.*)$ http://www.domain.com  [NC,L,U]

According to the examples at http://httpd.apache.org/docs/2.0/misc/rewriteguide.html, you do not need to use the backslash on the question mark.

Here's a handy online test tool for checking your rules: http://martinmelin.se/rewrite-rule-tester/

Using that I was able to get your url to work properly using the following rule:

RewriteRule ^mbc-ex/?(.*) http://www.domain.com [NC,L,U]


You need the QSD|qsdiscard flag

^/mbc-ex  http://www.domain.com [NC,L,U,QSD]

Since apache2 2.4.0

Pre 2.4.0: Add a ? to the end of you new url

^/mbc-ex  http://www.domain.com? [NC,L,U]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号