Q:

How to redirect URL if it contains "?"?

I've come up with
RewriteEngine on
RewriteRule ^(.*)?(.*)$ http://google.com [P]

but this approach works for addresses without ? - it is meant to work only for those with ?.
When I try to escape ? with /? - I have redirect no matter if URL has ? or doesn't,
when I escape ? with \? - I end up with no redirect at all.

A:

? is part of QUERY_STRING and not REQUEST_URI, and so you cannot check it directly in the rule itself.
You can check for the presence of the ? by checking either QUERY_STRING or THE_REQUEST:
# Check that QUERY_STRING is not empty:
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^ http://google.com/ [P]

# Check for the presence of a question mark in THE_REQUEST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s+(.+)\?(.+) [NC]
RewriteRule ^ http://google.com/ [P]

