Welcome to WebmasterWorld Guest from 54.145.117.127

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Block access to website by country?

     
7:41 pm on Apr 23, 2011 (gmt 0)

New User

10+ Year Member

joined:Mar 24, 2006
posts: 13
votes: 0


Does anyone know of a good way to block access to a website, depending on what country the user is accessing it from? E.g. I only want to allow UK visitors access and block the rest of the world, and redirect them to a page.

I've had quite an extensive Google search and so far can only find this: [countryipblocks.net...] which lets you block whole regions via IP address, but you have to do it by individual IP addresses, which you put in your htaccess file - once done, the htaccess file was 3mb! Wayyy to big

And.. I've seen the HTML5 geo-location but it's only supported by new browsers.


Any ideas?

Thanks
Ben
10:07 pm on Apr 23, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13066
votes: 308


Did you mean that literally? Allow one country, deny all (or just a few) others? In that case it seems like you'd be better off switching to "Deny,Allow" followed by "Deny from all" and then just a few lines for the ones you do want to let in.
10:25 pm on Apr 23, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The IP address method in the .htaccess file is the most efficient.

Be aware that blocking non-UK access will also remove your site from Google's index as they access from US-allocated IPs.

What about UK citizens abroad, on holiday, ex-pats, military, etc. Do you want to block all of them too?
4:21 pm on Apr 25, 2011 (gmt 0)

Full Member

5+ Year Member

joined:Oct 22, 2010
posts:302
votes: 0


the .htaccess method is quite cumbersome and not that accurate. The most accurate and up to date database is the maxmind.com paid geoip database. They also have a free version that is only 95% accurate.

If you use this, it's better to whitelist things than blacklist them. When you blacklist then when new IPs come (e.g. in a country you want to block), they won't be blocked until you update the database.

If you are implementing such a database with PHP or some scripting language, you could also choose to allow user-agent= googlebot to access your site. That would leave a backdoor for some guys who go around surfing as google bot, but there are some tradeoffs.

Another method would be to have a page somewhere that is not linked to anywhere on your site, and also not geo-blocked, then get it indexed by google, and then google bot can crawl your site via that url.