HOW TO: Block entire countries from your site

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 משתמשים שמצאו מאמר זה מועיל
?האם התשובה שקיבלתם הייתה מועילה

מאמרים קשורים

Can you map my domain/a subdomain to a typepad blog/photo album?

Domains or subdomains can be mapped to blogs or photo albums (or other materials) hosted at...

HOW TO: Combat referer spam/block certain referers

Symptom: A client wishes to deny access to their site (or parts of it) when the traffic is...

My phpBB forum installation is not accessible

Symptom: Client cannot access phpBB forum installation. Permissions on the forum installation...

Using mod_rewrite and .htaccess

Symptom: Client would like to redirect their main site to a subdomain under it. Using the...

What nameservers should be used for my account?

For servers in the Greek series, the following nameservers should be used:ns.hmdnsgroup.com -...