Vectro Web Hosting Knowledgebase
Main ::Proxy Sites ::Country Management
Minimize Text   Default    Enlarge Text

How do I block specific countries from accessing my web site?

Access to the mod_geoip module is included with all accounts. mod_geoip allows you to block certain countries from accessing your site. To do this, follow these instructions:

Step 1: FTP in to your site and go to your public_html directory.

Step 2: Download the file called .htaccess.

Step 3: Open .htaccess in a text editor and locate this section, which should be at or near the top:

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry
Deny from env=BlockCountry

Each line that starts with SetEnvIf blocks a different country. You will notice near the end of each line is a two-digit country code. For example, the country code CN belongs to China. Notice that the first line blocks this country.

Step 4: To add a country to the block list, first find the two-digit code for the country you want to block using this list of country codes.

Step 5:  Now that you know the code for the country you wish to block, add the following line ABOVE the Deny from env=BlockCountry line:

SetEnvIf GEOIP_COUNTRY_CODE XX BlockCountry

Just replace XX with the two-digit country code you selected from the list.

For example, let's say you selected Egypt. This is what your new code might look like. Notice EG added at the bottom for Egypt:

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE TW BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE HK BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE SA BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE IR BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE NG BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE EG BlockCountry
Deny from env=BlockCountry

NOTE: You can test your block rule by adding your own country and then removing it after you have tested.


If you are having trouble setting up a block rule or if you receive an error, please contact support.




Related Articles
How do I redirect traffic from specific countries?
Access to the mod_geoip module is included with all accounts. mod_geoip allows you to redirect traffic from certain countries which you specify. This is good if you have...
How do I log sites my users visit with PHProxy?
If you are comfortable modifying code, here is a quick cut-and-paste code tweak for PHProxy which logs the sites your users visit. This can come in handy to track misuse...
How do I block individual IP addresses?
It is possible to block an individual IP address from accessing your web site. To do this, follow these instructions: Step 1: Log in to your cPanel. Step 2: Once you...

 

Search Glossary Saved Articles Submit A Support Request Get Hosted at Vectro