Mod_rewrite (htaccess) QSA and removing charactes from appended query string

I've been struggling with some htaccess redirects. I just spent some time reading and searching and couldn't get a solution that works with my scenario.

I'm in the process of making the 301 redirect for an old website (ASP) to a new one (Wordpress). The old pages has parameters query which I need to process but also remove 'http://' string from it to get redirect to work.

Example URL (old) to redirect looks like:

redirected to:

and .htaccess code to redirect it:

RewriteCond %{QUERY_STRING} ^documentid=2410(&.*)$ [NC]
RewriteRule ^index\.asp(.*):(.*)$ [L,R=301,QSA]

but somehow is not working as I have expected when

RewriteCond %{QUERY_STRING} ^documentid=2410(&.*)$ [NC]
RewriteRule ^index\.asp$ [L,R=301,QSA]

works fine when I will remove http:// or : from a query string.

Where do I have made mistake?



Try this rule:

RewriteCond %{QUERY_STRING} ^documentid=(\d+)(&.+?)http://(.+)$ [NC]
RewriteRule ^index\.asp$ [L,R=302,NC,NE]

Make sure to clear browser cache before testing this.