RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|fr|de|it)/favicon.png$ favicon.png [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|fr|de|it)/assets(.*)$ assets$2 [L,QSA]
RewriteRule ^en/iphone/info6html en/iphone/info6.html [L]
RewriteRule ^de/iphone/info.html3 de/iphone/info3.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|fr|de|it)?(\/)?(.*)$ index.php?c=$1&q=$3 [L,QSA]
<?php
//make sure the plugin does not run on the mgr context (the manager)
if ( $modx->context->get( 'key' ) != 'mgr') {
/**
* grab the current context from the request "c" parameter (or context_param_alias from system settings)
* the alternative .htaccess friendly URL rewrite rule must be activated
*/
$cntxt_param = $modx->getOption('context_param_alias', null, 'c');
if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
switch ( $_REQUEST[$cntxt_param] ) {
case 'en':
//switch the context
$modx->switchContext('web');
//set the cultureKey
$modx->setOption('cultureKey', 'en');
break;
case 'fr':
$modx->switchContext('fr');
$modx->setOption('cultureKey', 'fr');
break;
case 'de':
$modx->switchContext('de');
$modx->setOption('cultureKey', 'de');
break;
case 'it':
$modx->switchContext('it');
$modx->setOption('cultureKey', 'it');
break;
default:
// Set the default language/context here
break;
}
}
}
$_SERVER['HTTP_ACCEPT_LANGUAGE']
$_SERVER['HTTP_ACCEPT_LANGUAGE'];
<?php
//make sure the plugin does not run on the mgr context (the manager)
if ( $modx->context->get( 'key' ) != 'mgr') {
switch ( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) {
case 'fr':
$modx->switchContext('fr');
$modx->setOption('cultureKey', 'fr');
break;
case 'de':
$modx->switchContext('de');
$modx->setOption('cultureKey', 'de');
break;
case 'it':
$modx->switchContext('it');
$modx->setOption('cultureKey', 'it');
break;
default:
$modx->switchContext('web');
//set the cultureKey
$modx->setOption('cultureKey', 'en');
break;
}
}
$cntxt_param = $modx->getOption('context_param_alias', null, 'c');
if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
switch ( $_REQUEST[$cntxt_param] ) {
Thanks, but I need the:
$cntxt_param = $modx->getOption('context_param_alias', null, 'c'); if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) { switch ( $_REQUEST[$cntxt_param] ) {
Right?
Just thought of another option: You could use theThat was also my suggestion. It's good in case someone calls the website without a language suffix. In other cases, the URL path evaluation should take over.variable in your gateway plugin, that might be easier.$_SERVER['HTTP_ACCEPT_LANGUAGE']
<?php
// get lang from URI
$uri= ($_SERVER['REQUEST_URI']);
$langFromUri = substr($uri, 1, 2);
switch ($langFromUri) {
case 'zh':
//set the cultureKey
$modx->setOption('cultureKey', 'zh');
break;
case 'en':
//set the cultureKey
$modx->setOption('cultureKey', 'en');
break;
case 'de':
//set the cultureKey
$modx->setOption('cultureKey', 'de');
break;
default:
// detect language and call corresponding start-page
$langPrefered = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($langPrefered) {
case 'en':
$targetId = 2;
break;
case 'zh':
$targetId = 3;
break;
default:
$targetId = 1;
$langPrefered="de";
break;
}
//set the cultureKey
$modx->setOption('cultureKey', $langPrefered);
//call correct start page
$url=$modx->makeUrl($targetId);
$modx->sendRedirect($url);
break;
}
return;