For reasons that aren\'t worth going into here, Google have been indexing one of my sites with an unnecessary query string in the URL. I\'d like to modify my htaccess file t
Try this (i tested it with your examples and it is working fine):
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&?query=[^&]+&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L]
Also, you should add a condition to apply this rule only on existing files (that's up to you).
If you want it:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{QUERY_STRING} ^(.*)&?query=[^&]+&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L]