Regex .htaccess RewriteRule用查询字符串重写条件,但不将查询字符串添加到最终url

Regex .htaccess RewriteRule用查询字符串重写条件,但不将查询字符串添加到最终url,regex,.htaccess,mod-rewrite,Regex,.htaccess,Mod Rewrite,我想重写以下规则: 查询字符串必须以choice1或choice2开头 查询字符串仅包含一个其他值 域应该是最终url的路径 最终url不应包含查询字符串 最终url的路径中应包含查询字符串的两个值 到目前为止(在这里的帮助下): 条件很好。 但最终url不包含查询字符串(%1和%2)的值。 虽然我不使用QSA标志,但也会附加查询字符串。 一些例子: first-domain.de?choice1&abc => https://www.mysite.de/link/choice1/

我想重写以下规则:

  • 查询字符串必须以choice1或choice2开头
  • 查询字符串仅包含一个其他值
  • 域应该是最终url的路径
  • 最终url不应包含查询字符串
  • 最终url的路径中应包含查询字符串的两个值
  • 到目前为止(在这里的帮助下):

    条件很好。 但最终url不包含查询字符串(%1和%2)的值。 虽然我不使用QSA标志,但也会附加查询字符串。

    一些例子:

    first-domain.de?choice1&abc => https://www.mysite.de/link/choice1/abc/first-domain
    first-domain.de?choice2&xyz => https://www.mysite.de/link/choice2/xyz/first-domain
    second-domain.de?choice1&ttt => https://www.mysite.de/link/choice1/ttt/second-domain
    second-domain.de?choice2&xyz => https://www.mysite.de/link/choice2/xyz/second-domain
    
    您可以使用此规则:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING}#%{HTTP_HOST} ^(choice1|choice2)&([^&#]+)#(?:www\.)?([^.]+)\. [NC]
    RewriteRule ^ https://www.mysite.de/link/%1/%2/%3? [L,NE,R=302]
    

    在单一条件下使用
    %{QUERY_STRING}{HTTP_HOST}
    的原因是我们只能使用最新的
    RewriteCond
    来捕获值
    %1
    %2
    %3
    等。

    您能添加一些源URL和目标URL的示例吗
    RewriteEngine On
    
    RewriteCond %{QUERY_STRING}#%{HTTP_HOST} ^(choice1|choice2)&([^&#]+)#(?:www\.)?([^.]+)\. [NC]
    RewriteRule ^ https://www.mysite.de/link/%1/%2/%3? [L,NE,R=302]