How to block access to the site by unwanted visitors.

1. Blocking bots on UserAgent. Add to the .htaccess line file:

SetEnvIfNoCase User-Agent ^ BadBot getout

SetEnvIfNoCase User-Agent ^ EvilBot getout

Order Allow, Deny

Allow from all

Deny from env = getout

Then we enter this file in the basic directory of the site (usually public_html) and the bots on UserAgent with the beginning of BadBot and EvilBot will not be able to access the site.


2. We block Referrer traffic. By adding the .htaccess file line:


SetEnvIfNoCase referer "^ http: //bad.domain.com/evilscript.php" blocked = 1

Order Allow, Deny

Deny from env = blocked

Allow from all

Then we enter this file in the main folder of the site (usually public_html) and the script http://bad.domain.com/evilscript.php will no longer be able to send you traffic.


3. We block traffic by country

Add to .htaccess:


SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry

SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry

(And so on for all the countries you want to block)

Deny from env = BlockCountry

Was this answer helpful?

 Print this Article

Also Read

How to protect yourself from Brute Force Attack against ftp and ssh (bruteforce attacks).

Rare are servers today, which are not subject to constant attempts of bruteforce attacks.It's...

How to restrict access to server management to everyone except me?

*Advanced Linux Knowledge and only for FreeBSDKeep in mind that the careless use of the firewall...