Forums / Setup & design / Multiple multilingual sites/domains on one EZ installation

Multiple multilingual sites/domains on one EZ installation

Author Message

Andreas Tremel

Monday 12 February 2007 8:34:24 am

Hello there,

I'm trying to setup the following:

Two/More Domains (domain1.com, domain2.com, ....)
Two/More Languages (german=de, english=en, ....)

I want to have different layouts for the domains (e.g. think of different products).
The language should be part of the url, uniformely accessible like this:
domain1.com/en/
domain1.com/de/
domain2.com/en/
domain2.com/de/

Everything works fine with ONE domain.

Now my problem: According to docs and the forum, I should solve the language part via two siteaccesses named "en" and "de". This sounds practically, at first. But, as I have two domains: I need "de" and "en" twice ... for each domain! Since each siteaccess is a folder, they can only exist once. Normal behavior is that the site access'es name is encoded in the url exactly. Consequence: for the second domain there can be no "de" or "en" siteaccess, obviously.

My question: can EZ publish be configured to resolve a siteaccess named "domain1en" to an alias named "en" in the url? That would solve my problem.

Anybody an(other) idea?
(Multiple site with multiple languages should have been realized on a singleton installation in the past, I think.)

Regards,

Andreas Tremel

Claudia Kosny

Monday 12 February 2007 2:01:18 pm

Hi Andreas

Theoretically eZ could match the 'en' in an Url to the siteaccess 'domain1en', the problem is only that it does not consider the host when doing the matching. So domain1.com/en would be matched to the same siteaccess as domain2.com/en.

The easiest solution to your problem would be to set up the languages as subdomain of the specific domain:

[SiteAccessSettings]
MatchOrder=host
HostMatchType=map
HostMatchMapItems[]=de.domain1.com;domain1de
HostMatchMapItems[]=en.domain1.com;domain1en
HostMatchMapItems[]=de.domain2.com;domain2de
HostMatchMapItems[]=en.domain2.com;domain2en

This makes it fairly easy to setup additional domains and the urls still look nice.

Another option could be to use htaccess to set a servervariable that sets the siteaccess.
As one can use mod_rewrite to set servervariables it is very flexible. Just set
MatchOrder=servervar and specify in your htaccess/virtual root config to set some servervariable to the name of the siteaccess for a certain pattern of urls (check the docu of mod_rewrite). The name of the servervariable is specified in site.ini.

Claudia

Andreas Tremel

Tuesday 13 February 2007 1:47:06 am

Hi Claudia,

thank you for the quick reply! I need the language in a dir, not in a subdomain.
We're migrating a large strutcture and do not want to change the uris because of seo/partner links reasons.

Thats my site.ini override to manage the siteaccess. As you can see, the subdomains are also configured, but they are only an alternative access. Main access should be domain1.com/en/

[SiteSettings]
DefaultAccess=en
SiteList[]=de
SiteList[]=en

[SiteAccessSettings]
ForceVirtualHost=true
CheckValidity=false
AvailableSiteAccessList[]=corporate_site_admin
AvailableSiteAccessList[]=de
AvailableSiteAccessList[]=en
MatchOrder=host;uri
HostMatchMapItems[]=www.de.domain1.com;de
HostMatchMapItems[]=www.en.domain1.com;en
HostMatchMapItems[]=admin.domain1.com;corporate_site_admin
URIMatchType=element
URIMatchElement=1 

Thats the rewrite module section of the vhost. All domains are hosted here:

    	#<IfModule mod_rewrite.c>
        	RewriteEngine On
        	Rewriterule ^/var/storage/.* - [L]
        	Rewriterule ^/var/[^/]+/storage/.* - [L]
        	RewriteRule ^/var/cache/texttoimage/.* - [L]
        	RewriteRule ^/var/[^/]+/cache/texttoimage/.* - [L]
        	Rewriterule ^/design/[^/]+/(stylesheets|images|javascript)/.* - [L]
        	Rewriterule ^/share/icons/.* - [L]
        	Rewriterule ^/extension/[^/]+/design/[^/]+/(stylesheets|images|javascripts?)/.* - [L]
        	Rewriterule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
        	RewriteRule ^/packages/styles/.+/thumbnail/.* - [L]
        	RewriteRule ^/favicon\.ico - [L]
        	RewriteRule ^/robots\.txt - [L]
        	Rewriterule ^/support/.* - [L]
        	RewriteRule .* /index.php
    	#</IfModule>

Could you give me an example how to modify these files to set servervariables and read them via site.ini?

Regards,

Andreas

Claudia Kosny

Thursday 15 February 2007 2:22:26 pm

Hmm, I have just tried it out and have encountered some serious problems:
Setting a server variable depending on an uri is pretty easy

RewriteEngine On
RewriteCond %{HTTP_HOST} domain1\.com
RewriteRule ^en  -  [E=SITEACCESS:domain1en]
RewriteRule ^de  -  [E=SITEACCESS:domain1de]

but the problem is that you still have the 'en' or 'de' in your url, which causes eZ to bring up an error that the module is missing. The next problem is that the urls created by eZ do not have the 'en' or 'de', so you get a major problem there.
Similar problems with patching the access.php to match for the beginning of an uri, e.g. www.domain.com/de, to a siteaccess. The matching is very easy to do, but you would have to fix ezuri,ezsys,whatever so the urls contain the part which is used for matching without considering them as a module. Not sure how difficult this is, but it takes more than the 15 minutes I tried.

Sorry, unfortunately I can't help you there.

Claudia

Andreas Tremel

Friday 16 February 2007 2:26:13 am

Hello Claudia,

thnak you for the hint. It's eassier than I expected, however modification of the files lib/classes/ezsys.php and access.php is necessary.

This thread describes it:
http://ez.no/community/forum/developer/running_two_multilingual_sites_on_a_single_ezp_installation/

The trick: you actually have 4 siteaccesses:
site1_de
site1_en
site2_de
site2_en

When an URL is parsed or generated, the "siten_"-part is added to the url or truncated from it.
It works for EZ 3.8.4.

Regards / Mit freundlichen Grüßen,

Andreas

Claudia Kosny

Friday 16 February 2007 5:14:03 am

Hi Andreas

Thats is good to know.I failed with adapting the eZsys class. Some of the urls had the siteaccess part doubled (e.g domain1.com/en/en/products), some did not have it at all, and I could not find out why this happened.

If you have a working solution - could you post your patches here? No need for something fancy, just post the code and the lines where it should be added/changed.

Thanks

Claudia

Andreas Tremel

Friday 16 February 2007 5:44:48 am

Hello Claudia,

Apply these changes (wroks for EZP 3.8.4.):

1. file: access.php, function: "accessType( &$uri, $host, $port, $file )", line ~123:

before:

else if ( $match_type == 'element' )
{
  $match_index = $ini->variable( 'SiteAccessSettings', 'URIMatchElement' );
  $elements = $uri->elements( false );
  $elements = array_slice( $elements, 0, $match_index );
  $name = implode( '_', $elements );
}

after:

else if ( $match_type == 'element' )
{
  $match_index = $ini->variable( 'SiteAccessSettings', 'URIMatchElement' );
  $elements = $uri->elements( false );
  $elements = array_slice( $elements, 0, $match_index );
  //$name = implode( '_', $elements );
  $hostname = explode(".",$host);
  $name = $hostname[1]."_".implode( '_', $elements ); 
}

2. file: lib/ezutils/classes/ezsys.php, function: "function addAccessPath( $path )", line ~813:

before:

function addAccessPath( $path )
{
  if ( isset( $this ) and get_class( $this ) == "ezsys" )
    $instance =& $this;
  else
    $instance =& eZSys::instance();
  if ( !is_array( $path ) )
    $path = array( $path );
    $instance->AccessPath = array_merge( $instance->AccessPath, $path );
}

after:

function addAccessPath( $path )
{
  $modified_path = explode("_",$path);
  $path = $modified_path[1];

  if ( isset( $this ) and get_class( $this ) == "ezsys" )
    $instance =& $this;
  else
    $instance =& eZSys::instance();
  if ( !is_array( $path ) )
    $path = array( $path );
    $instance->AccessPath = array_merge( $instance->AccessPath, $path );
}

That's it.

Regards / Mit freundlichen Grüßen,

Andreas

Claudia Kosny

Friday 16 February 2007 5:56:25 am

Hi Andreas

Thanks, I'll try it over the weekend.

Claudia