Restrict access to directory or domain by IP, using .htaccess
I don’t blah too much on this subject.
Basically, you can restrict or allow who can connect to your site or who can access specific directories using .htaccess .
Here’s the code to block one specific IP, I use 192.168.0.1 to block, you replace it with the IP you want to deny.
order allow,deny
deny from 192.168.0.1
allow from all
That is. Placed in the root of your site, the user with the IP 192.168.0.1 will not be able to access your site at all. If you place it in a specific subdirectory of your site, the user won’t access the specific subdirectory. If you want to put more IPs in your deny list, just add one more deny line for each IP.
To block by domain, replace the IP with a domain. For example:
order allow,deny
deny from .comcast.net
deny from .google.com
allow from all
If you look hard, you will observe that I put a dot in front of the domains. It has only one meaning: if you put a dot in front of the domain, all the sub-domains will be blocked. For example, in the second deny rule i said to deny everybody from google.com, including www.google.com, googlebot.google.com, finance.google.com, you get it.
And as always, we saved the world again.

Recent Comments