To block a specific IP from accessing your website, you need to use the “.htaccess“ file. Below, we provide some code examples for different situations. You only need to copy them into your .htaccess file, replacing the example IPs and domains with the IPs and domains to which you want the described rules to apply.
Allow all access except from IP xxx.xxx.xxx.xxx:
# This code allows all access except from the specified IP
order allow,deny
allow from all
deny from xxx.xxx.xxx.xxx
Allow all access except from IP xxx.xxx.xxx.xxx and the domain ejemplo.com:
# This code allows all access except from the specified sources
order allow,deny
allow from all
deny from xxx.xxx.xxx.xxx
deny from .*ejemplo\.com.*
Block all access except from IP xxx.xxx.xxx.xxx and the domain ejemplo.com:
# This code denies access to everyone except the specified sources
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
allow from .*ejemplo\.com.*
Block access originating from one or more domains:
# This code blocks visitors originating from the specified domains (For example, access from a link on that domain)
RewriteEngine on
RewriteCond %{HTTP_REFERER} ejemplo1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ejemplo2\.com [NC]
RewriteRule .* - [F]