Skip to main content
All CollectionshPanelOther
How to Block an IP Using the .htaccess File
How to Block an IP Using the .htaccess File

Blocking IP addresses with the help of the .htaccess file

Updated over a year ago

If you want to block or whitelist specific IP addresses, you can do it with an IP Manager.

If you prefer doing changes via .htaccess or you want to create settings for a list of addresses, all you need to do is:

  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

And by using * for the whole octets:

Order Allow,Deny
Deny from 185.185.*.*
Allow from all

That's it! Now you know how to block or allow IP addresses using .htaccess rules 😊

Did this answer your question?