Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Geo/IP Subdomain Redirection

Geo/IP Subdomain Redirection

Hello,
I am looking at Chameleon as a solution hopefully. I need to redirect users to different subdomains based on their country.
E.g. users from UK are redirect to uk.domain.com and users from Ireland are redirected to IRL.domain.com.
The subdomains will be separate independent sites.
Will Chameleon be able to fulfil this requirement?
Thanks in advance,
John

mackenj
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Re: Geo/IP Subdomain Redirection

Hi John,

yes, Chameleon can do this, with as much flexibility as you need.

i.e. there are a number of permutations of this you might require:
1 - Do you want the redirections to go ONLY from main domain out to the country-specific subdomains? What happens if someone from Ireland hits the uk.domain.com site?
2 - Are all the domains set up on the same Joomla installation, or are they completely different sites?
3 - If you are redirecting someone from domain.com/some_page to the UK version, do you want to send them to uk.domain.com or uk.domain.com/some_page? You can set this up with Chameleon to redirect to the same relative URL on the other domain.

In the simplest case, with 3 completely separate web sites and redirecting people who come from UK and IRL to the front page of their respective sites, you set this up in Chameleon as follows:

1 - Set up a Chameleon rule to detect GeoIP country GB, then in the Succeed action enter a redirect to url http://uk.domain.com/
2 - Set up a Chameleon rule to detect GeoIP country IE, then in the Succeed action enter a redirect to url http://irl.domain.com/

Simple!
Best regards
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Geo/IP Subdomain Redirection

I have made such a script,  here i check the  browser lan code, took me some time to find the vars at the end of the php page, was rather expecting them in the implementation and installation section, or at least have a hint that the vars are defined there.

Besides that really great tool.

a List of samples beside the 3 installed and a little more documentation, eg the cookies, etc would be fine.

/* check if gtans cookie with lan has been set, then use val */
/* if cookie is set and gtranslan is other then set the new language */
/* if no cookie is set use the browser setting for lan */
/* check if lan = geoip country */

ini_set('display_errors', 'On');
ini_set('html_errors', 0);
error_reporting(-1);

if(isset($_SERVER['HTTP_X_GT_LANG'])) {
$current_lang = $_SERVER['HTTP_X_GT_LANG'] ;
$current_lang = substr($current_lang,0,2);
$returninguser = 1;
}else{
$current_lang = '' ;
$returninguser = 0;
}
$domain= 'mydomain.com';
$browser_language = substr($language,0,2);

if(isset($_COOKIE['sitecalled'])) {
$cookie_sitecalled = trim($_COOKIE['sitecalled']);
}else{
$cookie_sitecalled = '';
}

$redirect = 0; $redirlan = '';
/* here all variations will be dealt with */
if($cookie_sitecalled == '' and $current_lang == '' ) {
/* NO cookie , default WP - set browser lan */
$redirect = 1;
$redirlan = $browser_language;
} if($cookie_sitecalled != '' and $current_lang == '' ) {
/* EXISTING cookie found , default WP - set cookie lan */
$redirect = 1;
$redirlan = $cookie_sitecalled;
} if(($cookie_sitecalled != '' and $current_lang != '') and ($cookie_sitecalled !=$current_lang) ) {
/* EXISTING cookie found , Choose new lan site - set cookie lan now I need to check if these are the same or not, otherwise I will run in circles */
$redirect = 1;
$redirlan = $current_lang;
}

if($redirect == 1) {

if($redirlan == 'zh') {
header("Location: http://zh-cn.".$domain);
} elseif ($redirlan =='en'){
header("Location: http://en.".$domain);
} elseif ($redirlan =='ro'){
header("Location: http://ro.".$domain);
} elseif ($redirlan =='fi'){
header("Location: http://fi.".$domain);
} elseif ($redirlan =='fr'){
header("Location: http://fr.".$domain);
} elseif ($redirlan =='sk'){
header("Location: http://sk.".$domain);
} elseif ($redirlan =='cz'){
header("Location: http://cz.".$domain);
} elseif ($redirlan =='ru'){
header("Location: http://ru.".$domain);
}

else {
header("Location: http://en.".$domain);
$redirlan ='en';
}
setcookie('sitecalled', $redirlan, time()+1000000000,'/','.'.$domain);
return true;
}else{}

/* echo "Browser:".$language."_cookie:".$cookie_sitecalled."_Gtrans_call".$current_lang; */

waltergrimmvie
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Geo/IP Subdomain Redirection

Hi Walter,

thanks for all the feedback and for sharing your code. I hadn't known about the GTranslate cookie before, so that's really useful to know.

Will work on documentation in due course.

Thanks
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Geo/IP Subdomain Redirection

metamodguy wrote:

1 - Set up a Chameleon rule to detect GeoIP country GB, then in the Succeed action enter a redirect to url http://uk.domain.com/
2 - Set up a Chameleon rule to detect GeoIP country IE, then in the Succeed action enter a redirect to url http://irl.domain.com/

Hi Stephen,
I've bought chameleon a few minutes ago, and I am lost. I just need to redirect users from Spain to es.mysite.com, and other  countries each to their respective to country.mysite.com
How do I setup these rules (it sounds so simple, but I see too many options there in backend). Please help me. just a screenshot or two would be of great help. I have a deadline in 10 hours and my job is hanging of a very thin line. .  smile
Regards

EDIT. I did it myself.

For the reference to people who will come here in the future. You need to change these tabs only:
Details tab
http://prntscr.com/idvmg1
Config tab:
http://prntscr.com/idvn14
Quick Rules tab:
http://prntscr.com/idvn83

And ACTIONS tab, this part ONLY:
http://prntscr.com/idvnvg

Tags for this post: How to redirect to subdomain with Chameleon Joomla, Geo IP redirect, GEOIP redirect Joomla Chameleon, Joomla site redirection based on country visitor, IP geolocation Joomla redirection

GREATLIBERO
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Geo/IP Subdomain Redirection

Hi Greatlibero,

you beat me to it! Thanks for updating the request with screenshots.
I just want to clarify one thing – the "preferred list of languages" doesn't do what you think it does. In your case, it doesn't do anything at all. It only takes effect when you use "Most preferred language from supplied list" from "$language handling".  And even then, it's only going to affect the "only these languages" or "Exclude these languages" boxes. You didn't display a screenshot of these - I assume you didn't use them.

So in your case, I think it's only the GeoIP that's doing anything, rather than any language checking.

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Geo/IP Subdomain Redirection

metamodguy wrote:

I just want to clarify one thing – the "preferred list of languages" doesn't do what you think it does. In your case, it doesn't do anything at all. It only takes effect when you use "Most preferred language from supplied list" from "$language handling".  And even then, it's only going to affect the "only these languages" or "Exclude these languages" boxes. You didn't display a screenshot of these - I assume you didn't use them.

Thanks Stephen,
I used it because I didn't know if I need it or not, just in case smile

Thanks for the explanation!

Regards

P.S. Thanks for the partial refund too! Much appreciated. smile

GREATLIBERO
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5910
Total Posts Today:
1
User Info:
 
Total Users:
10144
Newest User:
leonard5412396
Members Online:
2
Guests Online:
294


Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked