How to block a User Agens in an .htaccess file?

In case there is too much traffic towards your website coming from different IP addresses with one and the same User Agent, the easiest option to restrict them is to block the User Agent. For that purpose you should open your .htaccess file for editing and add the following rules:

where you should substitute UserAgentName with the actual name of the User Agent. For example, if you want to block a User Agent named Textbot, what you should add is:

It is recommended to add them in the very beginning of the .htaccess file. If you want to block more than one User Agent (e.g. named SCspider, Textbot and s2bot), you can do that with the .htacces rules below:

To block the requests from machines with missing User Agent, add the following rules in your .htaccess file:



You find this article useful? Click here to learn more about SiteGround web hosting experts and what else we can do for you!