skip to Main Content

I have a php based web application in which I want to redirect user to sub domain based on their country such as nz, au, in etc.

What is the best way to do that?

Htaccess?
PHP?
JavaScript?

How can I do with the above options?

Or you guys can suggest any other way as well!

2

Answers


  1. Please! check this out:

    geoPlugin

    and there is more such way which is helpful.

    Edit

    Reference:

    1. geoPlugin class for PHP
    2. list of geo country codes

    Code:

    <?php
    
    $meta = unserialize(file_get_contents('http://www.geoplugin.net/php.gp? 
    ip='.$_SERVER['REMOTE_ADDR']));
    
    if($meta['geoplugin_countryCode']=='IT') 
    {
    }
    ?>
    

    For more details:

    PHP Geolocation Web Service

    Login or Signup to reply.
  2. Something like this (Pseudo code!):

    RewriteEngine on
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE}
    RewriteRule ^(.*)$ https://example.com/$1 [L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search