Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a site which is only for US/Canada/UK visitors. I don't want to make it visible to other visitors.

I tried to put IP ranges in .htaccess (Deny IP) but it does not work for me. May be I have inaccurate IP lists or I am doing something wrong.

share|improve this question
6  
This honestly a silly thing to do. I have no idea what your site is about, but really? What if some of your Canadian visitors are on vacation in Mexico? Or away on business? They can't see your content.... If it is truly not for some visitors, won't the visitors filter themselves out? I mean, how many time does someone have to visit your site to figure out it is not for them? What if someone wants to buy whatever you are selling for their Canadian cousin, etc. But let more in then less, otherwise you are limiting your own site's potential. –  Itai Mar 19 '11 at 2:14
    
Deny by IP will not work, the IP list is toooo big. You may try some Geotargeting solution gimmerank.com/en/KB/Help/Detail/… –  Eric Yin Feb 12 '12 at 20:48
1  
If it's an ecommerce site you can set your shipping options to only allow shipping to US, Canada, and UK. To deny by IP is ridiculously inefficient as there are so many IP's and changes all the time. If I land on a website which is clearly meant for residents of a particular country I hit the back button and leave. @Itai is right, you don't know where visitors are coming from or who they're buying for. –  Anagio Jul 7 '12 at 16:07
add comment

7 Answers 7

As has been pointed out, what you're trying to do is not going to work.

And it's not a good idea either. It's not how the internet works.

share|improve this answer
add comment

i am using this free generator that goes in the .htaccess file.

share|improve this answer
add comment

Blocking by IP isn't a good solution anymore. You already got some obvious problems this approach can lead into.

You may end allowing undesired people, and blocking desired ones. One question: what technologies are you allowed to use?

After all, you can use GEO Location features and extensions available for Java, PHP, Python, Ruby or even Javascript.

share|improve this answer
add comment

Maybe you can get user's IP adress, and control it on this site via cURL and get Country information. But I don't know, is this best way. This method will reduce performance.

share|improve this answer
add comment

You might end up with blocking a very long list of IPs. People here try blocking India, Philippines and Pakistan - maybe this could solve a part of your problem.

share|improve this answer
add comment

You can get country IP ranges from this website and add them to a .htaccess file in public_html. It doesn't take as long as you think.

http://www.countryipblocks.net/country-blocks/htaccess-deny-format/

Some of the comments above are correct though. Especially about traveling visitors. It depends what your site is used for. If you're selling CPA offers then fine, but if you have a membership site of some sort, I'd think twice.

Instead, look around for a script that will redirect visitors from undesirable locations.

share|improve this answer
add comment

You are probably not getting the answer you want because most of these people are from these countries and are offended... I see a need to block these countries and a few more to fight spam and people trying to hack your root server - like China... I get about 60-100 hack attempts everyday from China so I blocked the entire country and those spammy countries to (India, Indonesia, Pakistan...) The traffic from those countries is worthless anyway. In most cases you don't generate revenue from them anyway so why supply them with info and waste resources?

Use CSF and block the entire countries. It's the easiest way and uses the least amount of resources. http://configserver.com/cp/csf.html

share|improve this answer
1  
This is nonsense on so many levels... First off, the US has always been the primary originator of spam and still is. Secondly, large scale spam operations that produce the majority of email/web spam (i.e. those run by the likes of Scott Richter/Media Breakaway and other major players) routinely hijack large IP blocks from arbitrary countries (U.S., Russia, whatever will be most effective for delivery) to route their spam or set up their spam sites through, and hackers do the same thing with botnets. –  Lèse majesté Feb 12 '12 at 17:59
    
Lastly, not only is what you're suggesting a really pointless thing to do, proper geo-IP blocking should be done at the router level, which would at least have a better chance of stopping some common attacks. Though it still makes much more sense to use a DNSBL to block known bad neighborhoods rather than arbitrarily blocking entire countries while leaving your network open to entire other bad netblocks. –  Lèse majesté Feb 12 '12 at 18:25
add comment

protected by John Conde Jun 16 '13 at 17:18

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.