Forum Moderators: phranque
(.*)lang=..&lang=(..)$The (.*) matches "everything" and then you confuse the RegEx parser by saying after "everything" there's some other stuff.
/?lang=en&lang=en => /?lang=en
/index.php?id=15&lang=en&lang=it&lang=de => /index.php?id=15&lang=en&lang=de => /index.php?id=15&lang=de
/subdir/do.php?pid=22&gid=5&lang=fr&lang=it => /subdir/do.php?pid=22&gid=5&lang=it
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)lang=..&lang=(..)$
RewriteRule ^/(.*) /$1?%1lang=%2 [R=301,L]
^([^&]+&)*lang=(..)$ which reads "read characters that are 'not &' one or more times, until you find '&', and then repeat that function zero or more times until you find the final '&', then read 'lang=' and then capture the two final characters" in the backreference.