Query string in apache rewrite rule

I got a task to rewrite an URL from apache server :

http://site.foo.com/[Anything]

into

http://site.foo.com

I implemented a rewrite rule like this to cater for above case :
RewriteRule ^/(.*)$ http://site.foo.com [NC,L]

However, this rule fail to cater case with ? character like below :
http://site.foo.com/[Anything]?[Anything]

The above rule will rewrite above into something like :
http://site.foo.com/?[Anything]

To fix it , need to append “?” at the end of the rule in order to remove query string after ? , now the rules within Apache virtual host construct becomes :

……
RewriteEngine on
RewriteOptions inherit
RewriteRule ^/(.*)$ http://site.foo.com/? [NC,L]

You may also like...