Symptom: A client wishes to block all visitors from a particular country to their site. Can this be done?
Resolution: It is possible to block any visitor from a particular country by creating a .htaccess file with the appropriate "deny from" statements.
A .htaccess file is a plain text file placed into the web root (public_html) folder. This file contains directives as they relate to the client's site(s) only; that is, the directive in this file will be applied when requests are made to the client's site(s). The .htaccess is a recursive file: directives placed in a .htaccess that is under the public_html folder will also apply to any subfolder. Any .htaccess placed in a subfolder that duplicates values in a higher level .htaccess will override the values set in the higher level .htaccess.
EXAMPLES
Example 1
A client has domain.com at /home/username/public_html, and two subdomains at /home/username/public_html/sub1 and /home/username/public_html/sub2. The same client also has an addon domain that points to the folder /home/username/public_html/addon.
The client places a .htaccess in the public_html denying all traffic from IP space belonging to Korea. This will deny access from that IP space to anything under the client's web space, including subdomains and the addon domain.
The client subsequently places a .htaccess in the addon folder, containing the following line.
DirectoryIndex myindex.html
All traffic from Korean IP space will still be denied, but the directory index for this addon domain will be the file "myindex.html", regardless of any values set in the higher level .htaccess or at the system level.
Example 2
A client has domain.com at /home/username/public_html, and two subdomains at /home/username/public_html/sub1 and /home/username/public_html/sub2. The same client also has an addon domain that points to the folder /home/username/public_html/addon.
The client places a .htaccess in the public_html denying all traffic from IP space belonging to France. This will deny access from that IP space to anything under the client's web space, including subdomains and the addon domain.
The client subsequently places a .htaccess in the sub1 folder, which contains lines to allow traffic from certain IP ranges in France, in this format:
allow 1.2.3.0/24
The effect of this, if 1.2.3.0/24 was originally included in a deny from statement in the higher level .htaccess, would be to allow access from this IP range, but to deny access from any other ranges listed in that higher level .htaccess.
Does Hosting Matters have any ready-made deny lists available?
We do not maintain listings of IPs for this purpose. We recommend using data generated via Country IP Blocks using the ".htaccess deny" option.
- 1 Users Found This Useful