.htaccess 301 Redirect for Geo-targeting

Discussion in 'Apache' started by jimcraig, Aug 12, 2010.

  1. #1
    Like Schults, I know nothing!

    I would like to do some geo-targeting and have discovered that the country I am targeting has 167 blocks of ip addresses assigned to them. Some examples are :

    58.69.0.0 to 58.69.255.255
    58.71.0.0 to 58.71.127.255
    61.14.192.0 to 61.14.255.255

    The first line in the example goes the whole distance and I thought that I can write (okay, so I copied from another post in this Forum) the code as such:

    RewriteCond %{REMOTE_ADDR} ^58\.69\.
    RewriteRule ^index\.html$ http://www.philippines.sub.domain.net/ [R=301,L]

    Now here are my questions?

    1) What is wrong with the above code?
    2) How do I end an IP block that does not go the distance? Such as line two in the example above.
    3) How do I do multiple blocks? If I were to guess I would do something like the following code correct?

    RewriteCond %{REMOTE_ADDR} ^58\.69\.
    RewriteCond %{REMOTE_ADDR} ^61\.14\.192\.
    RewriteRule ^index\.html$ philippines.page.html [R=301,L]

    Thanks,

    Jim
     
    jimcraig, Aug 12, 2010 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    Personally I'd look at http://www.maxmind.com/app/mod_geoip

    However:
    
    RewriteCond %{REMOTE_ADDR} ^58\.69\. [OR]
    RewriteCond %{REMOTE_ADDR} ^61\.14\.192\.
    RewriteRule (.*) http://www.philippines.sub.domain.net/$1 [R=301,L]
    
    Code (markup):
    That sends the visitor to the same page but on the philippines subdomain.
     
    tolra, Aug 13, 2010 IP
  3. jimcraig

    jimcraig Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This helps. Thank you.

    Jim
     
    jimcraig, Aug 13, 2010 IP
  4. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #4
    the a.m. mod_geoip certainly is maintenance friendlier - you just update once a months the free geoip db
    else with the htaccess rewrite method
    you have to check every few days or weeks for new IP blocks assigned to the Philippines.

    make sure you include in your IP blocks all major mobile proiders in the PH such as

    smart, globe, pldt, etc besides traditional ISP IP blocks
     
    hans, Aug 15, 2010 IP
  5. jimcraig

    jimcraig Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Do you know if the mobile providers are included in the a.m. mod_geoip package? Thanks. Jim
     
    jimcraig, Aug 15, 2010 IP
  6. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #6
    I use the free geoIP db for my access_log stats and YES the major mobile ISP show up
    smart, globe, pldt
    for others i have no experience
    if you know of a local ISP IP or another mobile ISP, you may want to test
    http://www.maxmind.com/app/locate_demo_ip
    the free db is basically the same except only updated once a month and maybe less accurate (city/regional) data
     
    hans, Aug 15, 2010 IP