DESIGNfromWITHIN Reply #1, 5 months, 2 weeks ago
I wrote this post:
MODX Multilingual – Setting up Babel http://designfromwithin.com/blog/995/modx-multilingual-setting-up-babel/
It seems a lot of people are struggling with this.
Following this tut does not work 100%:
http://www.multilingual-modx.com/blog/2011/seo-friendly-multilingual-websites-with-modx-and-babel.html
I changed the tut a bit and I have got it to work now, but not exactly the way I want it.
What is working now:
What I would like:
The issue:
Some of the code used:
.htaccess:
Lexicons:
I have tried this, does not work:
Gateway plugin (OnHandleRequest checked):
MODX Multilingual – Setting up Babel http://designfromwithin.com/blog/995/modx-multilingual-setting-up-babel/
It seems a lot of people are struggling with this.
Following this tut does not work 100%:
http://www.multilingual-modx.com/blog/2011/seo-friendly-multilingual-websites-with-modx-and-babel.html
I changed the tut a bit and I have got it to work now, but not exactly the way I want it.
What is working now:
- http://mysite.com/en/ (default)
- http://mysite.com/nl/ (dutch)
- http://mysite.com/de/ (german)
What I would like:
- http://mysite.com/ (default)
- http://mysite.com/nl/ (dutch)
- http://mysite.com/de/ (german)
The issue:
How do I get the root link to work without having /com/en/ added behind it?
Some of the code used:
.htaccess:
RewriteEngine On
RewriteBase /
....
# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^your-website-url\.com [NC]
RewriteRule (.*) http://your-website-url.com/$1
[R=301,L]
....
# The Friendly URLs part
# detect language when requesting the root (/)
RewriteCond %{HTTP:Accept-Language} !^(en|nl|de) [NC]
RewriteRule ^$ en/ [R=301,L]
RewriteRule ^$ nl/ [R=301,L]
RewriteRule ^$ de/ [R=301,L]
# redirect all requests to /de/favicon.ico and /nl/favicon.ico
# to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|de|nl)/favicon.ico$ favicon.ico [L,QSA]
# redirect all requests to /de/assets* and /nl/assets* to /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|de|nl)/assets(.*)$ assets$2 [L,QSA]
# redirect all other requests to /de/* and /nl/*
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|de|nl)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
Lexicons:
base_url: /nl/
cultureKey: nl
site_start: 11
site_url: http://www.modxtutorials.com/nl/
base_url: /de/
cultureKey: de
site_start: 22
site_url: http://www.modxtutorials.com/de/
base_url: /en/
cultureKey: en
site_start: 1
site_url: http://www.modxtutorials.com/en/
I have tried this, does not work:
base_url: /
cultureKey: en
site_start: 1
site_url: http://www.modxtutorials.com/
Gateway plugin (OnHandleRequest checked):
<?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, 'cultureKey');
if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
switch ( $_REQUEST[$cntxt_param] ) {
case 'nl':
$modx->switchContext('Nederlands');
$modx->setOption('cultureKey', 'nl');
break;
case 'de':
$modx->switchContext('Deutsch');
$modx->setOption('cultureKey', 'de');
break;
default:
// Set the default language/context here
$modx->switchContext('web');
$modx->setOption('cultureKey', 'en');
break;
}
}
}
?>