How to ban bad bots in .htaccess?

Many cowling bots are bad for your website or maybe you want to ban some bots so they can’t access your website.

You need to create a .htaccess file in your root directory like /public_html/.htaccess or /public_html/somefolder/.htaccess

Note: If you will use .htaccess in sub-folder then it will work only on your specific directory and still crowler can access your main website like example.com but they can’t access example.com/somefolder because of you put a restriction in this folder.

Copy and paste this code as it is in your .htaccess file and If you want to ban other bots,crowlers then you can modify this code.

SetEnvIfNoCase User-Agent „AhrefsBot“ bad_bots
SetEnvIfNoCase User-Agent „rogerbot“ bad_bots
SetEnvIfNoCase User-Agent „mj12bot“ bad_bots
SetEnvIfNoCase User-Agent „semrushbot“ bad_bots
SetEnvIfNoCase User-Agent „sistrix“ bad_bots
SetEnvIfNoCase User-Agent „searchmetricsbot“ bad_bots
SetEnvIfNoCase User-Agent „archive.org_bot“ bad_bots

order allow,deny
allow from all
deny from env=bad_bots

How to ban bad bots in .htaccess?
Scroll to top