I have downloaded my access log file from my cPanel and found I have a bot I would like to stop. In the access log, there User-Agent string reads the following; - - [08/May/2014:23:29:52 -0500] "GET / HTTP/1.0" 301 - "-" "-" - - [08/May/2014:23:29:56 -0500] "GET / HTTP/1.0" 200 29019 "-" "-"

What is the proper format in my .htaccess file to block this bot only?

  • 1
    There is no user agent string in there
    – John Conde
    May 9 '14 at 19:20
  • Those are complete access log entries. The User-Agent is just the last part ie. "-" (a single hyphen, which probably represents an empty user agent string.)
    – MrWhite
    May 9 '14 at 20:20

To block all "blank" User-Agents or User-Agents consisting of a hyphen, you could use the following in your .htaccess

RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule ^ - [F]
  • can anyone explain how it works? ^-?$ what does it mean?
    – user4951
    Apr 25 '15 at 8:50
  • The first line indicates a conditional rewrite, in this case if the user-agent matches the regular expression which is blank with an optional - character. If the condition statement is true, then the rewrite rule on the next line is triggered. In this case the rewrite rule is to not rewrite the URL at all, but to return an HTTP forbidden code (403). Apr 25 '15 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.