How can I block a user agent from all sites on my server?

Looks like an old question now, but I wanted to do the same and found the answer from nerve above. It's not quite right as is - seems to me that it should be <Location "/">, and the SetEnvIf needs a regular expression so the parentheses need to be quoted.

This worked for me to apply the access control across all vhosts:

SetEnvIfNoCase User-Agent "^Mozilla/4.0 \(compatible; Synapse\)" bad_ua
<Location "/">
    Deny from env=bad_ua
</Location>

Just include that before the vhost definitions.


mod_rewrite can be configured at the server level according to the docs:

RewriteCond %{HTTP_USER_AGENT} "Mozilla/4\.0 \(compatible; ICS\)" [nocase]
RewriteRule ^.*$ - [forbidden,last]

Don't forget to escape the regex in the RewriteCond