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

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 different versions of your site for people in different countries. There are also of course many other reasons you may have to redirect traffic from specific countries. 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.

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

Step 5: Traffic can be redirected from one or multiple countries.

To redirect traffic from only one country, put this at the top of your .htaccess file:

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^XX$
RewriteRule ^(.*)$ http://www.example.com/somepage.html$1 [L]

Just replace XX with the country code you wish to block. Replace http://www.example.com/somepage.html with the URL you want the traffic redirected to.

Example of redirecting Canadian traffic to http://canada.example.com:

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://canada.example.com$1 [L]


To redirect traffic from multiple countries, use this instead:

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(XX|XX|XX|XX|XX|XX)$
RewriteRule ^(.*)$ http://www.example.com/somepage.html [L]

Just place each country codes you wish to block in place of each XX. You can have as few or as many country codes as you want. Replace http://www.example.com/somepage.html with the URL you want the traffic redirected to.

Example of redirecting traffic from China, Taiwan, Hong Kong, Saudi Arabia, Iran and Nigeria to http://test.example.com/info.html

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CN|TW|HK|SA|IR|NG)$
RewriteRule ^(.*)$ http://test.example.com/info.html [L]

NOTE: You can not redirect traffic to a page on the same domain. You MUST redirect traffic OUTSIDE of your domain. For instance, if your domain is example.com DO NOT redirect the traffic to example.com/stuff.html or any other page on example.com. Redirect it to a subdomain like stuff.example.com or to another domain altogether.

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

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




Related Articles
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...
I use forms on my web site. How can I have the information people fill into the form e-mailed to me?
FormMail Clone works almost exactly the same way as FormMail by Matt Wright from Matt's Script Archive. An example of why you would use FormMail close would be if you use...
What ports should I use?
The default port 110 is set up to handle incoming e-mail. Almost all e-mail programs set this automatically so there is no need to set this yourself. The default...

 

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