Redirect Visitors According To Country

Discussion in 'Site & Server Administration' started by wgn_white, Sep 18, 2008.

  1. #1
    Hi.

    Can anyone tell me how to redirect visitors according to their country?

    What I want to do is;

    1. Visitors from Malaysia(My country) will be redirect into subdomain where it is in Bahasa Melayu(Malaysian Language).

    2. Visitors from outside Malaysia will remain on the main domain.

    What is the .htaccess code?

    And, if the visitors from Malaysia choose to view the page in English, they will not be redirected back into the subdomain.

    Thanks in advance...
     
    wgn_white, Sep 18, 2008 IP
  2. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    .htaccess is apache file for multiple settings, redirection is just one of the options.

    If you know complete IP range for Malaysia set up a rewrite condition (if your server allows you to ... ) in htaccess to redirect tweaking code below

     RewriteEngine On
       RewriteBase /
       RewriteCond %{REMOTE_HOST} IP ADDRESS 
       RewriteCond %{REQUEST_URI} /index\.html$
       RewriteRule .* http://Malaysia.yoursite.com [R=301,L]
    Code (markup):
    HTH
     
    pubdomainshost.com, Sep 18, 2008 IP
  3. wgn_white

    wgn_white Active Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Well, by IP?
    Then how to add several IP address in here?

    RewriteCond %{REMOTE_HOST} IP ADDRESS
    Code (markup):
    And my website is using generator. (Wordpress)
    How do I feel this?
    RewriteCond %{REQUEST_URI} /index\.html$
    Code (markup):
     
    wgn_white, Sep 18, 2008 IP
  4. nimhost

    nimhost Active Member

    Messages:
    235
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #4
    create an index.html because index.html is have more priority then index.php then setup a javascript which can look on geoip location database then redirect it based by geoip database

    try search on google their is many of the source about this :)
     
    nimhost, Sep 18, 2008 IP
  5. jliu

    jliu Peon

    Messages:
    235
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If your site is hosted on a VPS or dedicated server and you can install software, install MaxMind's GeoIP database and mod_geoip. If you are on shared hosting you could ask them to install it.

    You would then do this replacing Canada's country code (CA) with Malaysia's:

    RewriteEngine on
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
    RewriteRule ^(.*)$ http://www.redirectedsite.com$1 [L]
     
    jliu, Sep 18, 2008 IP
  6. wgn_white

    wgn_white Active Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #6
    Thank you...
    I will try this.
     
    wgn_white, Sep 18, 2008 IP
  7. nimhost

    nimhost Active Member

    Messages:
    235
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #7
    this is the real answer i never know :p

    mod_geoip is available for apache 2.2 too ?

    and can i put more then 1 country ?
     
    nimhost, Sep 18, 2008 IP
  8. Neutron

    Neutron Well-Known Member

    Messages:
    701
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #8
    I have a slightly different issue. Using
    RewriteEngine on
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CA|US|UK)$
    RewriteRule ^(.*)$ http://www.northamerica.com$1 [L]
    Code (markup):
    I can redirect visitors from Canada/US/UK to the site northamerica.com

    But for something different, I only want to allow visitors from Canada/US/UK on my site and redirect everyone else to northamerica.com.

    How should the reg exp be changed in the above rewrite rule to do this?
     
    Neutron, Jan 8, 2009 IP
  9. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #9
    buldozerceto, Jan 9, 2009 IP