[solved] Multiple domains, same site with MLE

This is a FORK of the CMS Made Simple project and is not oficially supported in any way by the CMS Made Simple development team.
Locked
peterfarrington
New Member
New Member
Posts: 8
Joined: Wed Jun 03, 2009 10:12 am

[solved] Multiple domains, same site with MLE

Post by peterfarrington »

Hi

I am porting a multilanguage site over from a proprietary system to CMSMS MLE.

Everything is fine. The data is all uploaded for the multiple languages.

I have one issue however before I can switch over the sites.

There are multiple domains all pointing to the same space. So company.co.uk, company.de, company.eu etc etc.

In the proprietary system the programmer checks for the domain being used to access the site and then manages the correct set of language pages. Of course he can code up whatever he wants.

In CMSMS MLE I have the English site appearing as the default for all the domains at the moment, and I have the flags in the footer so I can switch between languages. But there is a flash banner with flags which link to the domain names, so the French flag goes to company.eu and the German flag to company.de. I have the CMSMS MLE install in a subdirectory so I have put an index.php file in the root which checks the domain name being used and the redirects to the CMSMS install using the following form of URL....

newsite/index.php?page=about&hl=de_DE

This correctly opens the German language version.

BUT if I use the CMSMS flags then whenever I access a menu option for the rest of that session it seems to have recorded that the language being used is the one based on the CMSMS flag.

So I am in the Dutch site, everthing is in Dutch, then I click on the link in the flash banner and go to the French domain, the index.php redirects to...

newsite/index.php?page=trial&hl=fr_FR

as required, but when I click on a menu link to go to...

newsite/index.php?page=projects

I see the Dutch version of the page again.

So I am confused about where a cookie or something is being set to show the current language. I was rather expecting that going to...

newsite/index.php?page=trial&hl=fr_FR

for instance, would fix the current language as French, for example, but obviously it isn't.

Any pointers for changing languages based on what I am trying to do would be most appreciated.

Thanks

Peter
Last edited by peterfarrington on Wed May 05, 2010 7:50 pm, edited 1 time in total.
Peciura

Re: Multiple domains, same site with MLE

Post by Peciura »

Language is chosen in following order:
   1. $_POST['hl']
   2. $_GET['hl']
   3. $_COOKIE['mle']
   4. $_SERVER['HTTP_ACCEPT_LANGUAGE'] //visitor preferred language
   5. $_SERVER['HTTP_USER_AGENT']  //visitor preferred language
   6. default language from "MLE languages"
After language is chosen $_COOKIE is set for 5 hours, buts still $_GET is preferred.

Normally if links are generated by MenuManager  therre should not be any link without url tail "&hl=??_??"


IMO it is not necessary to install CMSms-mle-fork to subfolder.
Just set them as aliases. 
Then  write UDT that checks alias on $_SERVER['HTTP_HOST'] and then sets $_GET['hl'] accordingly.
All subsequent links will be created on $config['root_url'] basis.

If problems persists - post link to page.
peterfarrington
New Member
New Member
Posts: 8
Joined: Wed Jun 03, 2009 10:12 am

Re: Multiple domains, same site with MLE

Post by peterfarrington »

Thanks for the helpful breakdown of how the system checks language requirements.

I have not used menu_manager for this site yet as the client has a very static main menu, and the target was to get the site duplicated as quickly as possible and then work on developing the CMSMS installation.

I put the CMSMS install in a subfolder because I didn't want any possibility of messing up their live site.

There are 5 domains all pointing to the same space which actually exists on the .nl domain. If I visit the .nl domain I can switch between languages fine using the CMSMS flags. It remains completely consistent. But I need to also do something with the flag links in the flash banner - since that is part of the site design, and they are hardcoded to go to the 5 domains. So I thought I would just need to create a PHP script that redirected the browser based on the domain name.

So here are a few lines from that script...

Code: Select all

$site = $_SERVER["HTTP_HOST"];

if($site == "www.somesite.co.uk"){
header("location: http://www.somesite.co.uk/newsite/index.php?page=trial&hl=en_UK");
}
I rather expected that visiting that address would then set the language to be en_UK for all subsequent page views. What I have found though is that although it opens the UK language home page fine, the subsequent pages are then in a different language which I guess has been picked up elsewhere.

If I redirect to the .nl domain then it seems that everything works consistently, and so this...

Code: Select all

$site = $_SERVER["HTTP_HOST"];

if($site == "www.somesite.co.uk"){
header("location: http://www.somesite.nl/newsite/index.php?page=trial&hl=en_UK");
}
goes to the.nl domain and shows the en_UK home page and then continues to browse the site in English as expected (or any other variant).

So the issue I am having seems to be to do with switching the domains. The config.php is set as follows..

Code: Select all

$config['root_path'] = '/home/somesite.nl/public_html/newsite';
I wonder if this is affecting how cookies are set? And is that affecting multi-domain browsing of the site? I am happy to set a cookie in my index.php file based on the visiting domain if that would work, but I am not entirely sure where it is going wrong and what I need to do.

As I say, if I restrict the browser to the .nl domain where the CMSMS is really living then everything works OK, but if the browser is trying to view it using .co.uk. or .de, or .eu then it is (I guess) picking up a language from a cookie created previously.

If you can help at all I will be very grateful.

Peter
Peciura

Re: Multiple domains, same site with MLE

Post by Peciura »

...I am not entirely sure where it is going wrong and what I need to do...
Link like this

Code: Select all

newsite/index.php?page=projects
unsets language in $_GET and other steps determines language (up to default language).

If you are using links without urltail "&hl=$lang" then create UDT that saves language to $_COOKIE['mle'] every time new page is opened. E.g {save_lang}:
/*$params['lang']*//*mandatory*/

global $hls;
if (!empty($params['lang']) && !empty($hls) && $params['lang'] != $_COOKIE['mle']){
if ( array_key_exists($params['lang'], $hls)){
setcookie('mle', $params['lang'], time()+1800);
}
}
Call it at the very top of the page
{assign var='smarty' value=$gCms->GetSmarty()}
{save_lang lang="`$smarty.get.hl`"}
. (description about template processing can be found here http://forum.cmsmadesimple.org/index.ph ... #msg203281)
Last edited by Peciura on Tue Apr 13, 2010 12:12 pm, edited 1 time in total.
peterfarrington
New Member
New Member
Posts: 8
Joined: Wed Jun 03, 2009 10:12 am

Re: Multiple domains, same site with MLE

Post by peterfarrington »

Thanks very much for your help, it is much appreciated.

I have created a UDT called save_lang with the code you provided, and at the top of each template I have added the folllowing code...

Code: Select all

{assign var='smarty' value=$gCms->GetSmarty()}
{save_lang lang="`$smarty.get.hl`"}
I am still having a problem however. What I have noticed is that whichever of the various domains I go to, such as .eu or .co.uk, all of the URLs on the site are pointing to the domain, companyname.nl. Is this because in config.php the $config['root_url'] is set to the .nl domain?

Is the config.php page called for each CMS page view? If so, could I change the value of $config['root_url'] programatically based on the domain? I am wondering if when the browser is directed to .co.uk, for instance, a cookie may be set, but if all the links point to .nl then when he clicks on a link he ends up using the value for the language held in a cookie under the .nl domain?

I will try to change the $config['root_url'] programmatically, as well as use the code you provided. If this is wrong and you come on line before I finish, I'd appreciate a little more help.

Thanks

Peter
Peciura

Re: Multiple domains, same site with MLE

Post by Peciura »

I am still having a problem however. What I have noticed is that whichever of the various domains I go to, such as .eu or .co.uk, all of the URLs on the site are pointing to the domain, companyname.nl. Is this because in config.php the $config['root_url'] is set to the .nl domain?
Yes

I would not hack file "/config.php".

This line generally just duplicates value that is already saved in {$lang}

Code: Select all

{save_lang lang="`$smarty.get.hl`"}
After you reload page any variables can be not valid any more. That is what global variables like $_COOKIE, $SESSION are for. Set $_COOKIE['mle'] as soon as you change language. I just named UDT "save_lang". Place it at the very top of page template, it is important to  save language as soon as it is know.
peterfarrington
New Member
New Member
Posts: 8
Joined: Wed Jun 03, 2009 10:12 am

Re: Multiple domains, same site with MLE

Post by peterfarrington »

Thanks for all your help.

Following your instructions I have got the multiple language - multiple domains impementation working.

Peter
Peciura

Re: Multiple domains, same site with MLE

Post by Peciura »

Welcome.
Add [Solved] to the title of your first message.
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Re: Multiple domains, same site with MLE

Post by Foaly* »

Peciura wrote: IMO it is not necessary to install CMSms-mle-fork to subfolder.
How can I achieve this?
Peciura

Re: [solved] Multiple domains, same site with MLE

Post by Peciura »

Creating site alias is apache stuff. Google for directives 'Virtual Host', 'ServerName' and 'ServerAlias'.

Here are links to tips how to set root url dynamically.
http://forum.cmsmadesimple.org/index.ph ... #msg214289
or even
http://forum.cmsmadesimple.org/index.ph ... 890.0.html
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Re: [solved] Multiple domains, same site with MLE

Post by Foaly* »

Okay, sorry, that isn't what I'm searching for. I actually managed to setup both domains, but still there's a lang folder in my url:

englischdomain.com/en/file.html
germandomain.de/de/file.html

Is it possible to remove the lang folder?
Peciura

Re: [solved] Multiple domains, same site with MLE

Post by Peciura »

ATM there are no other means to handle languages and pretty url in CMSms-mle-fork.
There is at least one thread on building mixed urls recently posted to forum.
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Re: [solved] Multiple domains, same site with MLE

Post by Foaly* »

Hm, not the answer I wanted you to give ;D Nevertheless, thank you.
Locked

Return to “[locked] CMSMS MLE fork”