We earn commission when you buy through affiliate links.
This does not influence our reviews or recommendations.Learn more.
I hope you already have a list of referer and user-agent you want to block.
Lets get it started.
Nginx
Nginx power millions of sites and very popular amongweb hosting.
If you are using Nginx, then here is how you might stop them.
If you would you like those to redirect somewhere, then:
The above configuration must be under theserverblock.
And the following to block by referrers.
The following example which should go under thelocationblock for blocking requests from semalt.com, badsite.net, example.com.
After making necessary changes, you oughta save the file and restart Nginx to take effects.
Apache HTTP
To block user-agent in Apache, you could use themod_rewritemodule.
Ensure the module is enabled and then add the following in either.htaccessfile or respective.conffile.
The above rule will block any request containing user-agent as badcrawler, badbot, and badspider.
And, the below example to block by the referrer name BlowFish, CatchBot, BecomeBot.
As usual, restart the Apache server and to test the results.
If you are looking for comprehensive security protection, then you may also consider using cloud-based WAF likeAstraorSUCURI.