Q:

URL rewrite to exclude certain HTML files

I need to URL write uppercase URLs to lowercase. 
I got that part working.
However, I am having problem. I am interested in excluding from the above *.html?vs=12312312 
I tried the following:
RewriteCond %{REQUEST_URI} !^.*\.(html\?vs=) [NC]

But it didn't work. 
http://foo.com/com.foo.bar/content/Any.html?vs=12312312

The above should stay the way it is, and not be rewritten. 
What's wrong with the rule above? What should be the proper syntax?
Update
I tried the following:
RewriteCond %{REQUEST_URI} !(.*\.html\?vs=.*)$ [NC]

But still no luck. 

A:

The query string is not part of the REQUEST_URI, it is stored in QUERY_STRING. So try something like this, which goes before your existing rule:
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{QUERY_STRING} ^vs=[^&=]+$
RewriteRule ^ - [L]

The reason you need to do it this way (as its own separate rule), rather than putting an exclusion on your existing rule, is because you can't do AND with negative matches of RewriteCond, so putting them on your existing rule as negative matches would prevent it from running if only one applied (.html or ?vs=nnn). To reject when both apply, you need to do it in a separate, positive match like this.
If you have other rules you need to apply to those URLs after this, look at the [S=1] flag (documentation) which will skip the next rule on a match, instead of [L] which says stop processing here after a match (and hence don't apply your subsequent rules for these URLs).
The rule RewriteRule ^ - just says don't change anything, it's used to only apply the effect of the flags.

