I have a site translated in 2 languages - English and Spanish.

The English site is on example.com, the Spanish site is on example-SPANISH.com, so I set the "language detection method" based on the domain.

Now, the english site has a slightly different content based on the exact location of the users, so I have created different languages like EN-US, EN-GB, EN-CA, etc...

I want to set this (sub)language based on a GET parameter, like this

example.com/?from=england -> sets language to EN_GB
example.com/?from=canada -> sets language to EN_CA

I could use the Session detection method as primary one, but I want to prevent (for duplicate content \ SEO reasons) the spanish site to return the english content if the ?from parameters is set.

In other words, this URL


mustn't set the language to EN_CA: it should remain ES_ES instead.

Any ideas on how to achieve this?

I was thinking about a function like this in a custom module:

function MYMODULE_boot() {

 if(isset($_GET['from'])) {

 $allowedLangs = array(

  'www.example.com' => array('en', 'us', 'ca'),
  'www.example-SPANISH.com' => array('es')


 if( in_array($_GET['from'], $allowedLangs[$_SERVER['HTTP_HOST']]) )
  $_SESSION['from'] = $_GET['from'];



The problem is that when the ?from param is set in the URL, whatever i set in _SESSION seems to get ignored.

  • On a quick glance it seems that the session detection syste, uses the from parameter as well to set the language. So it might overwrite your sessions somewhere later in the code execution. Try to unset the $_GET['from'] to prevent this from happening. Perhaps the detection then falls back to the session? Feb 23, 2014 at 18:56


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.