使用多个参数查询字符串重定向htaccess

时间:2015-03-30 15:01:57

标签: apache .htaccess mod-rewrite parameters

我想重定向一个包含多个参数的网址,并重命名参数键:

 www.site.it/index.php?par1=1&lang=en_US

 www.site.com/index.php?parameter1=1&languages=en_US

我试过这个:

RewriteCond %{QUERY_STRING} par1=([0-9]+)
RewriteCond %{QUERY_STRING} lang=en_US
RewriteRule ^index.php site.com/index.php?parameter1=$1&lang=en_US [R=301,L]

但它失败了。

1 个答案:

答案 0 :(得分:0)

您可以使用:

RewriteCond %{QUERY_STRING} par1=(\d+)&lang=([^&]+)
RewriteRule ^index\.php http://www.example.com/index.php?parameter=%1&languages=%2 [R,L]

%1%2是对查询字符串regex中捕获组的引用