Blocking “Empty User Agent String” Website Visits

Case: Logs in cPanel Awstats show a high number of hits from `empty user agent string` bots which cause high CPU usage and/or traffic.

Solution

Add to the following directives to .htaccess:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^-?$
# allow request from Cron; mind the dollar sign after the IP:
RewriteCond %{REMOTE_ADDR} !^YOUR_SERVER_IP_ADDRESS$
RewriteRule ^ - [F,L]

References

Did this solve your issue?