.htaccess 如何在Htaccess中忽略url参数字符串的结尾?

.htaccess 如何在Htaccess中忽略url参数字符串的结尾?,.htaccess,.htaccess,我有一堆丑陋的链接进入这样一个网站: https://www.somedomain.com/mm5/mch.mvc?Session_ID=5f59c6e0&Screen=PRODFB&Product_Code=pcode1&Category_Code=category_a&Store_Code=store1&fb=1 https://www.somedomain.com/mm5/mch.mvc?Screen=PROD&Product_Code=p

我有一堆丑陋的链接进入这样一个网站:

https://www.somedomain.com/mm5/mch.mvc?Session_ID=5f59c6e0&Screen=PRODFB&Product_Code=pcode1&Category_Code=category_a&Store_Code=store1&fb=1
https://www.somedomain.com/mm5/mch.mvc?Screen=PROD&Product_Code=pcode1
RewriteCond %{QUERY_STRING} Screen=PRODFB&Product_Code=([^&]+)
RewriteRule ^(.*)$ /mm5/mch.mvc?Screen=PROD&Product_Code=%1& [R=301,L,NE]
我正在尝试使用htaccess重新创建url,如下所示:

https://www.somedomain.com/mm5/mch.mvc?Session_ID=5f59c6e0&Screen=PRODFB&Product_Code=pcode1&Category_Code=category_a&Store_Code=store1&fb=1
https://www.somedomain.com/mm5/mch.mvc?Screen=PROD&Product_Code=pcode1
RewriteCond %{QUERY_STRING} Screen=PRODFB&Product_Code=([^&]+)
RewriteRule ^(.*)$ /mm5/mch.mvc?Screen=PROD&Product_Code=%1& [R=301,L,NE]
我已经想出了这个办法,但它当然不起作用。我想我只需要能够忽略product_code参数之后的url参数的其余部分,但不确定如何做

RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^Screen=PRODFB&Product_Code=([^/.]+)$ /mm5/mch.mvc?Screen=PROD&Product_Code=$1 [R=301,L,NE]

我错过了什么?谢谢

您无法匹配
RewriteRule
指令中的查询字符串

只要查询参数与所讨论的参数相同,就可以在站点根目录中使用此规则。htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} /(mm5/mch\.mvc)\?.*&Screen=PRODFB&(Product_Code=[^\s&]+) [NC]
RewriteRule ^ /%1?Screen=PROD&%2 [R=301,L,NE]
或者使用
%{QUERY\u STRING}

RewriteCond %{QUERY_STRING} (?:^|&)Screen=PRODFB&(Product_Code=[^&]+) [NC]
RewriteRule ^mm5/mch\.mvc/?$ %{REQUEST_URI}?Screen=PROD&%1 [R=301,L,NE]

我能让它像这样工作:

https://www.somedomain.com/mm5/mch.mvc?Session_ID=5f59c6e0&Screen=PRODFB&Product_Code=pcode1&Category_Code=category_a&Store_Code=store1&fb=1
https://www.somedomain.com/mm5/mch.mvc?Screen=PROD&Product_Code=pcode1
RewriteCond %{QUERY_STRING} Screen=PRODFB&Product_Code=([^&]+)
RewriteRule ^(.*)$ /mm5/mch.mvc?Screen=PROD&Product_Code=%1& [R=301,L,NE]

谢谢,但是我需要将param Screen=PRODFB更改为Screen=PROD,我可以调整上面的示例以实现这一点吗?这对我来说不起作用,我认为%{the_REQUEST}存在问题,但我确实使用了下面发布的答案。感谢您的帮助,它为我提供了一些让这项工作正常运行的想法。您的规则与重写规则中的
*
相匹配,这意味着它还将重定向
/abc/123/?Session\u ID=5f59c6e0&Screen=PRODFB&Product\u code=pcode1&Category\u code=Category\a&Store\u code=store1&fb=1
而不仅仅是
/mm5/mch\.mvc
URI。请看我更新的答案,了解正确的用法。啊,很好。您的代码工作得很好,谢谢您的帮助。我将把这个标记为答案。