Anu Furlan
Anu Furlan

Reputation: 13

redirect with multiple parameter query strings htaccess

I want to redirect an url with multiple parameters and rename the parameters keys:

From

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

to

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

I tried with this:

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]

But it failed.

Upvotes: 0

Views: 4296

Answers (1)

arco444
arco444

Reputation: 22881

You can use:

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

%1 and %2 are references to the capture groups in the query string regex

Upvotes: 1

Related Questions