Last active
October 19, 2023 07:08
-
-
Save netProphET/8e29c06cee9ab8b8fab2 to your computer and use it in GitHub Desktop.
MODX Cloud web rules example for Babel with two languages.In this example, German is the default language with resources in the 'web' context; English is the secondary language, set up in the 'en' context.This technique is based on the "SEO Friendly Multilingual Websites" article archived here: https://web.archive.org/web/20180927220103/http://w…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if($modx->context->get('key') != "mgr"){ | |
/* grab the current langauge from the cultureKey request var */ | |
switch ($_REQUEST['cultureKey']) { | |
case 'en': | |
/* switch the context */ | |
$modx->switchContext('en'); | |
break; | |
default: | |
/* Set the default context here */ | |
$modx->switchContext('web'); | |
break; | |
} | |
/* unset GET var to avoid | |
* appending cultureKey=xy to URLs by other components */ | |
unset($_GET['cultureKey']); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
site_url http://site.com/de/ | |
base_url /de/ | |
cultureKey de | |
--- also recommended to provide resource ids for the following settings | |
error_page (id) | |
site_start (id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
site_url http://site.com/en/ | |
base_url /en/ | |
cultureKey en | |
--- also recommended to provide resource ids for the following settings | |
error_page (id) | |
site_start (id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set $lang de; | |
# choose the language that appears first in the accept_language header | |
if ($http_accept_language ~* "(de|en)") { | |
set $lang $1; | |
} | |
location ~ ^/$ { | |
rewrite ^ $lang/ redirect; | |
} | |
location ~ ^/(de|en) { | |
# redirect favicon.ico and assets/* requests to site root | |
rewrite ^/(de|en)/(favicon.ico|assets.*)$ /$2 redirect; | |
# main Babel rewrite | |
rewrite ^/(de|en)/(.*)$ /?cultureKey=$1&q=$2 break; | |
# MODX rewrite | |
try_files $uri $uri/ @modx-rewrite; | |
} | |
location / { | |
try_files $uri $uri/ @modx-rewrite; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. You made my day!