There are a few ways that you can stop this:
- mod_rewrite can match on query string
- mod_security can block this, and a number of other attempts to abuse your server
- if the clients use SNI, you can set up a separate virtual host for the other domain and block everything to it, and log to a separate file (or to /dev/null)
- let the requests through, but don't log them
For mod_rewrite, there's a canonical question with lots of information. A basic ruleset for this could be
RewriteEngine On
RewriteCond %{QUERY_STRING} ?p=foo.git.*
RewriteRule .* - [F]
This will return 403 Forbidden
to the client.
For mod_security, see the documentation at modsecurity.org.
For virtual hosts, see the documentation at the apache documentation site. Note that there may be a problem with clients who don't use SNI, as per the question Understand ssl setup
For changing the logging, you can use a combination of mod_rewrite, environment variables and custom log format. Here's an example:
RewriteEngine On
RewriteCond %{QUERY_STRING} ?p=foo.git.*
RewriteRule .* - [F,E=nolog:1]
CustomLog /path/to/your/access.log common env=!nolog