Khan Sharukh
Khan Sharukh

Reputation: 1201

What is the best way to redirect user to sub-domain(au, nz etc) based on country?

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!

Upvotes: 1

Views: 147

Answers (2)

kwoxer
kwoxer

Reputation: 3833

Something like this (Pseudo code!):

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE}
RewriteRule ^(.*)$ https://example.com/$1 [L]

Upvotes: 0

Utkarsh Dubey
Utkarsh Dubey

Reputation: 776

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

Upvotes: 1

Related Questions