简体   繁体   English

htaccess重写规则附加查询字符串参数

[英]htaccess Rewrite rule appending query string parameters

I am trying to write a rewrite rule for below URLs: redirect 我正在尝试为以下URL编写重写规则:redirect

  • www.domain.com/mbc-ex to www.domain.com www.domain.com/mbc-exwww.domain.com
  • www.domain.com/mbc-ex?abcd=123 to www.domain.com www.domain.com/mbc-ex?abcd=123www.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 the query string parameters 上面的规则仍然附加了查询字符串参数

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

this one works as expected 这一个按预期工作

You need the QSD|qsdiscard flag 您需要QSD | qsdiscard标志

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

Since apache2 2.4.0 从apache2 2.4.0开始

Pre 2.4.0: Add a ? 2.4.0之前的版本:添加? to the end of you new url 到您的新网址的末尾

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

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. 根据http://httpd.apache.org/docs/2.0/misc/rewriteguide.html上的示例,您不需要在问号上使用反斜杠。

Here's a handy online test tool for checking your rules: http://martinmelin.se/rewrite-rule-tester/ 这是检查您的规则的便捷在线测试工具: 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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM