带查询参数的apache重写规则

带查询参数的apache重写规则,apache,.htaccess,url,mod-rewrite,url-rewriting,Apache,.htaccess,Url,Mod Rewrite,Url Rewriting,我需要用三个动态参数值重定向现有url。 我现有的url类似于: http://localmach.test.it:90/aa/nonLoggedUser.portal?appb=true&event=AppEvent&Code=1.564&mobile=789754654&locale=en 现在我想用相同的参数将其重定向到不同的ip,如: http://17.22.11:90/aa/mycare?appb=true&event=AppEvent&am

我需要用三个动态参数值重定向现有url。 我现有的url类似于:

http://localmach.test.it:90/aa/nonLoggedUser.portal?appb=true&event=AppEvent&Code=1.564&mobile=789754654&locale=en
现在我想用相同的参数将其重定向到不同的ip,如:

http://17.22.11:90/aa/mycare?appb=true&event=AppEvent&Code=1.564&mobile=789754654&locale=en
我正在httpd.conf文件中使用ApacheURL重定向。 我能够重定向没有参数的url,但无法重定向参数存在

我已经尝试在httpd.conf中重写下面的内容,但它不起作用

<VirtualHost *:90>
  ServerName localmach.test.it
  RewriteEngine on
  RewriteCond %{QUERY_STRING} ^Code=([0-9]*)&mobile=([0-9]*)&locale=([a-z]*)$
  RewriteRule ^/(.*)(aa/nonLoggedUser.portal?appb=true&event=AppEvent&)(.*)$ http://17.22.11:90/aa/mycare?appb=true&event=AppEvent&Code=%1&mobile=%2&locale=%3$

</VirtualHost> 

ServerName localmach.test.it
重新启动发动机
重写cond%{QUERY_STRING}^Code=([0-9]*)和mobile=([0-9]*)和locale=([a-z]*)$
重写规则^/(.*)(aa/nonLoggedUser.portal?appb=true&event=AppEvent&)(.*)$http://17.22.11:90/aa/mycare?appb=true&event=AppEvent&Code=%1&mobile=%2&locale=%3$
请帮忙 提前谢谢

  • 参数
    code
    不是查询字符串中的第一个参数,因此之前的
    ^
    将不匹配
  • 您不能在
    重写规则
    模式中匹配查询字符串
  • 此外,用于匹配查询参数的正则表达式也不正确
  • 您不能在目标URI中使用正则表达式,因此
    $
    在那里被视为一个文本
    $
  • 您可以使用此重构规则:

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} (?:^|&)(Code=[^&]*&mobile=[^&]*&locale=[^&]*)(?:&|$) [NC]
    RewriteRule ^/?aa/nonLoggedUser\.portal$ http://17.22.11:90/aa/mycare?appb=true&event=AppEvent&%1 [L,NC,NE,R=301]