Quote from: donquicky at Jan 25, 2013, 04:40 PMI'am also afraid that it evaluates the system setting. In your script the cultureKey is set based on language served. Consider setting cultureKey by default on each context and not in a script. That way I believe the Redirector extra will redirect fine!
Thanks, I tried this:
Set [[++cultureKey]] in every context
Updated .htaccess
<?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');
break;
case 'fr':
$modx->switchContext('fr');
break;
case 'de':
$modx->switchContext('de');
break;
case 'it':
$modx->switchContext('it');
break;
default:
switch ( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) {
case 'fr':
$modx->switchContext('fr');
break;
case 'de':
$modx->switchContext('de');
break;
case 'it':
$modx->switchContext('it');
break;
default:
$modx->switchContext('web');
//set the cultureKey
break;
}
}
}
}
In Redirector:
promo.html >
[[!++cultureKey]]/promotion.html
Gets redirected to:
http://mysite.com/en/en/promotion.html (with every language setting it goes to EN)
or
promo.html >
promotion.html
Gets redirected to:
http://mysite.com/en/promotion.html (with every language setting it goes to EN)
also
promo.html >
http://mysite.com/[[++cultureKey]]/promotion.html
http://mysite.com/en/promotion.html (with every language setting it goes to EN)
So not there yet...
The Redirector code is:
<?php
/**
* @package redirector
*/
/* load redirector class */
$corePath = $modx->getOption('redirector.core_path',$scriptProperties,$modx->getOption('core_path').'components/redirector/');
$redirector = $modx->getService('redirector','Redirector',$corePath.'model/redirector/',$scriptProperties);
if (!($redirector instanceof Redirector)) return '';
/* handle redirects */
$search = $_SERVER['REQUEST_URI'];
$baseUrl = $modx->getOption('base_url',null,MODX_BASE_URL);
if (!empty($baseUrl) && $baseUrl != '/' && $baseUrl != ' ') {
$search = str_replace($baseUrl,'',$search);
}
$search = ltrim($search,'/');
$extPos = strrpos($search, '.');
if ($extPos) {
if ($search) {
$redirect = $modx->getObject('modRedirect', array(
'pattern' => $search,
'active' => 1,
));
if ($redirect) {
$target = $redirect->get('target');
$modx->parser->processElementTags('', $target, true, true);
if ($target != $modx->resourceIdentifier && $target != $search) {
if (!strpos($target, '://')) {
$target = $modx->getOption('site_url').$target;
}
$modx->log(modX::LOG_LEVEL_INFO, 'Redirector plugin redirecting request for ' . $search . ' to ' . $target);
header('HTTP/1.1 301 Moved Permanently');
$modx->sendRedirect($target);
}
}
}
$search = substr($search, 0, $extPos);
}
if ($search) {
$redirect = $modx->getObject('modRedirect', array('pattern' => $search, 'active' => 1));
if ($redirect) {
$target = $redirect->get('target');
$modx->parser->processElementTags('', $target, true, true);
if ($target != $modx->resourceIdentifier && $target != $search) {
if (!strpos($target, '://')) {
$target = $modx->getOption('site_url').$target;
}
$modx->log(modX::LOG_LEVEL_INFO, 'Redirector plugin redirecting request for ' . $search . ' to ' . $target);
header('HTTP/1.1 301 Moved Permanently');
$modx->sendRedirect($target);
}
}
}
return;
Maybe I can modify it?
[ed. note: ThaClown last edited this post 13 years, 8 months ago.]