fbpx

How to use .htaccess file to block an IP address

If you have problems with certain visitors to your website, you can easily block them by using their IP address or the domain name from which they are visiting.

  • Here’s an example that denies a user by their IP address:
deny from 111.111.111.111

When the user tries to connect to your site from that specific IP, they see a 403 Forbidden page instead. If you want to block an entire block of IPs, just leave the last octet off. For example:

deny from 111.111.111.

This denies access from anyone using an IP in the range from 111.111.111.0 all the way up to 111.111.111.255.

  • In order to block a domain, use the following:
SetEnvIfNoCase Referer "domainname.com" bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer

If you are a Host Duplex customer and still have questions, please open a ticket in the Host Duplex client portal.

Updated on December 29, 2021

Was this article helpful?

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.