Since this discussion is now in the Apache forum I am adding a more current example that can be used for those on Apache server who don't mind editing their .htaccess file. This version may have more current format on newer versions of Apache. I have used it for well over 15 years on various Apache versions.
This section should be with any rewrite rules and before your canonical rewrite rules. If you use WordPress, their WP snippet of code goes at the end of other rewrite rules.
RewriteCond %{HTTP_USER_AGENT} (A6|access|appid|blog) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (capture|client|crawl|curl) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (wget|win32|wotbox|wsr) [NC]
RewriteRule .* - [F]
This is not intended to be used as-is, it is a format. As you can see, you can add in 'parts' of UAs, the entire name is not needed, so long as you do not use portions of UAs that actual human visitors might have such as
(chr|moz|pera|safa)
within the parentheses.
Copying and pasting this into your .htaccess file will NOT fix any specific problem you are seeing on your site, it is intended only as a helper 'template' code and you will need to replace these UA bits with your own for best results.
The text within parentheses is separated by the pipe symbol: | which in this context means 'or'. That [NC,OR] flag at the end of each line means [either upper or lower case] and [see the next line for more]. Note that the last line of UAs does not include the [OR] flag. That [F] flag at the end means 'forbidden access' so those folks will get a 403 response. It does not prevent them from visiting to ask again but over time they may become discouraged at failures.
I'm sure I've left out something, so take it, adapt it, ask questions.