1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

htaccess to block countries

Discussion in 'Apache' started by miktor, Mar 15, 2007.

  1. #1
    hi, i recently opened a proxy website and a few people on this site told me that i should use .htaccess to block countries like iran since they use most of the bandwith. the only problem is that i have no clue on how .htaccess works and i need some guidence on setting it up
     
    miktor, Mar 15, 2007 IP
  2. evera

    evera Peon

    Messages:
    283
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To block a country you need the countries ip adresses.
    You can get them for example here: http://ip-to-country.webhosting.info/node/view/6

    Then you need to put this ip's in the htaccess file like this:
    order allow,deny
    deny from 127.0.0.1
    deny from 127.0.0.2
    deny from 127.0.0.3
    allow from all
    Code (markup):
    But its a lot of work, and the IP's are changing constantly..
     
    evera, Mar 17, 2007 IP
  3. miktor

    miktor Peon

    Messages:
    560
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    is that the only thing i need in the htaccess file? or are there more things that go into an htaccess file?
     
    miktor, Mar 17, 2007 IP
  4. evera

    evera Peon

    Messages:
    283
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    evera, Mar 17, 2007 IP
  5. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes that is, but do no use 127.0.0.1, etc. that are the localhost ranges. Use the IPs belonging to the countries that you want to block following the above link to find them out.
     
    Your Content, Mar 17, 2007 IP
  6. miktor

    miktor Peon

    Messages:
    560
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks to all, i will try this later on today
     
    miktor, Mar 17, 2007 IP
  7. wildcard

    wildcard Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hello,

    The most efficient and easy way is to block, or allow users from a certain country to visit your website is with the help of a so called .htaccess file on your server. In this .htaccess file you write which ip addresses should not have access and which ip addresses should have access.

    The website located on blockacountry.com gives a service where you can easily click on the countries you wish to block. Following blockacountry.com generates you a .htaccess document which you can upload to your server and there you go. As easy as 1,2,3.

    Wildcard
     
    wildcard, Jul 7, 2007 IP
  8. Jovial

    Jovial Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well is it ip range?
    which are the dangerous places other than china
    i dont support blocking whole east/asia
     
    Jovial, Jul 7, 2007 IP
  9. wildcard

    wildcard Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    At least block:

    Macao SAR China
    Hong Kong SAR China
    China
     
    wildcard, Jul 7, 2007 IP
  10. deny

    deny Active Member

    Messages:
    365
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #10
    deny, Jul 7, 2007 IP
  11. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #11
    I'm not sure, but perhaps the answer to the section below may help.

    A friend is experiencing massive problems on bandwidth and needs to use his htaccess to block certain countries, but it doesn't seem to work, any ideas please ? How could it be adjusted to work ?

    <limit GET>
    deny from BR, RU, CN, RO, SN, SK
    </limit>

    Any help very much appreciated.

    Kezi
     
    Kezi, Jul 9, 2007 IP
  12. wildcard

    wildcard Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Will not work... you need to use ip ranges

    Wildcard
     
    wildcard, Jul 9, 2007 IP
  13. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #13
    That's a massive shame, there would be about 80 countries in total = a lot of ip ranges = a big load every time a page is parsed.

    Also a lot of typing ;-(

    :confused:

    Kezi
     
    Kezi, Jul 9, 2007 IP
  14. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #14
    Or perhaps PHP ?

    [?php
    $country = geoip_country_code_by_name($_SERVER["REMOTE_ADDR"]);
    if (!(($country == "USA") or ($country == "CA") or ($country == "GB") or ($country == "AU"))) { die("Service Unavailable!"); }
    ?

    Obviously would need customizing to adapt, but has it got any potential ? Would be a lot easier than inputting 100's of numbers.
     
    Kezi, Jul 9, 2007 IP
  15. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #15
    Or maybe some of the info on the link below can be used ?

    <url>http://tinyurl.com/2h6mqh</url>
     
    Kezi, Jul 9, 2007 IP
  16. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #16
    How do the others here block multiple countries from viewing their websites please ? If you block say 15-20 countries, you're looking at a few hundred ip ranges ! Big hit on loading each page !!

    Any help very much appreciated.

    Kezi
     
    Kezi, Jul 12, 2007 IP
  17. Cybermonsters

    Cybermonsters Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Just FYI - I was looking up this thread for info on htaccess wildcard IP blocks - and I'm an expat working in Macao SAR. So please don't block us - some of us are the good guys. :)
     
    Cybermonsters, Apr 27, 2008 IP
  18. gonecrazy

    gonecrazy Guest

    Messages:
    605
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Found this post in a search result... is there any new ways to accomplish this? ( i noticed the post is 2 years old.)
     
    gonecrazy, Jun 28, 2010 IP