Skip to main content
< All Topics
Print

How to block an IP using the .htaccess file

1. Create a .htaccess file in your public_html folder
2.Add lines based on your preferences

Option 1 — Block or allow specific IP addresses

To set rules for specific addresses, you can use this template:

Order Allow,Deny
Deny from 185.185.185.185
Allow from all

In the example above, IP address 185.185.185.185 is blocked and won’t be able to reach your website.

If you want to block several addresses, add them from the new line:

Order Allow,Deny
Deny from 185.185.185.185
Deny from 192.192.192.192

NOTE

  • The Allow from line is optional if you only want to deny access and vice versa

Option 2 — Block or allow ranges of IP addresses

You can set rules for whole ranges or subnets of IP addresses by setting from-to values in IP address:

Order Allow,Deny 
Deny from 185.185.185.0/24 
Allow from all