# /etc/apache2/conf.d/ku-ban-baduseragents.conf
#
# ::copy::
# ::maintainer::
#
# ::do_not_edit::
# 
# forbid access based on user agents list (words, not regexp)
#
<IfModule mod_rewrite.c>
  #RewriteLog "/tmp/log"
  #RewriteLogLevel 3
  RewriteEngine On

  RewriteMap baduseragents txt:/etc/apache2/bad_useragent_map.txt

  # first component
  RewriteCond %{HTTP_USER_AGENT} "^([^ ][^ ]*)" [nocase]
  RewriteCond ${baduseragents:%1} REJECT [nocase]
  RewriteRule .* - [forbidden,last]

  # last component
  RewriteCond %{HTTP_USER_AGENT} " ([^ ][^ ]*)$" [nocase]
  RewriteCond ${baduseragents:%1} REJECT [nocase]
  RewriteRule .* - [forbidden,last]

  # 2nd last component
  RewriteCond %{HTTP_USER_AGENT} " ([^ ][^ ]*) [^ ][^ ]*$" [nocase]
  RewriteCond ${baduseragents:%1} REJECT [nocase]
  RewriteRule .* - [forbidden,last]
</IfModule>
