mod_rewrite with multiple QUERY STRINGS

Solution 1:

I was able to get this by adding the following condition and rule.

RewriteCond %{QUERY_STRING} ^(.*)(%2520)(.*)(%2520)(.*)$
RewriteRule ^(.+)$ $1?%1_%3_%5 [R=301]

Unfortunately, I need to repeat this cond/rule for however many spaces may come up. I tried a bunch of different conditions and rules [N] didn't seem to ever do what it was supposed to do.

I'm still open for answers as I feel this can be done better, more reliably, and/or more robust.