htaccess Rewrite rule appending query string parameters
I am trying to write a rewrite rule for below URLs: redirect
www.domain.com/mbc-ex
towww.domain.com
www.domain.com/mbc-ex?abcd=123
towww.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]
精彩评论