Using Apache's mod rewrite how you can redirect foo.php?r=ok to boo.php (that's, depending the query string: if r = ok then redirect).

you cannot use query string (the string after "?" character) as variable for rewrite, because query string isn't a a part of URL path.

you have to modify foo.php?r=ok with a string path like "foo.php/redirect/"

From the Apache manual discussing mod_rewrite:

If you want to complement from the hostname, port, or query string, make use of a RewriteCond using the %, %, or % variables correspondingly.

Look carefully at RewriteRules and RewriteConditions

EDIT: Added a functional example

The RegEx use to create these is simply pure paradise </sarcasm>

Any how... here is a simple rule (Apache2, Mac OS X 10.5.8)

RewriteCond $1 ^(foo\.php)
RewriteCond %{QUERY_STRING} (r=ok) 
RewriteRule (foo\.php)      /bar.php [R]

I examined this as many apparent caveats which i could think about (ie r=ko, oof.php, foo.php?r=o), but could not break it.