XILO Ltd. : Blog

Support 0333 773 3000 • Sales 0800 905 5000


Our blog includes company news, recent announcements and upcoming service changes.

Blocking certain countries from viewing your website

We’re often asked if there is an easy way to block certain countries from viewing sites hosted on our servers. Whilst it has been possible in the past, it was complex and tricky to implement.

You may want to block individual counties from accessing your site because of a high amount of “comment spam” on your blog, or maybe you have a site that you need to restrict to certain countries due to the content being region specific. This is all possible using a quick .htaccess rule.

Since our switch to the LiteSpeed, this is very easy to implement and we’re going to give a brief guide on how to do this.

We’ve added a sample rule that blocks 6 locations where we see the most comment spam originate from on our own community forums; Brazil, China, India, Indonesia and Russia. We’re also going to add a filter for Anonymous Proxies.

You will need to create a .htaccess file and upload this to the directory you want to protect, or if the whole site, create in public_html.

Our sample content looks like this:

RewriteEngine on

GeoIPEnable On
RewriteRule ^(.*)$ http://www.google.co.uk$1 [L]

If the visitors IP address matches one of the counties listed on the “RewriteCond” line, it will then send them to http://www.google.co.uk as shown on the “RewriteRule” line. As it uses mod_rewrite, you could adapt this to only allow listed countries instead of rejecting them or even show specific content and languages for different regions.

When entering the country, the ISO code should be used. As an example, for United Kingdom you should use GB and not UK. There are also some addition codes to cover special locations as follows:

A1 - Anonymous Proxies
A2 - Satellite Providers
EU - Europe
AP - Asia and Pacific (ASIAPAC)
US - America but also includes overseas military bases regardless of country.

We hope you find this new feature very useful and this is one of many improvements that we are rolling out on all shared, reseller and premium hosting servers over the next few weeks.