We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50994
    • 7 Posts
    Actually... I wrote in PS of my first post that I don't want to use Accept-language as it may have any value in post-soviet countries for example where business language may drastically differ from browser default language.
    • discuss.answer
      • 37377
      • 64 Posts
      Last try: http://stackoverflow.com/questions/19570572/htaccess-multi-language-site-with-sub-directories-and-default-301

      Haven't tried it, but this solution looks pretty good at first sight.
        • 50994
        • 7 Posts
        Oh, it looks like everything works right now! Thank you!!!

        Once again, for those who got the same problem. My current setup:

        MODX 2.4.0, Babel 3.0.0 Beta 4. Two contexts for two languages. Every language is in separate context, no subfolders in MODX installation.

        Context configuration:
        web
        base_url ——— /en/
        cultureKey ——— en
        site_start ——— 1
        site_url ——— mysite.com/en/

        russian
        base_url ——— /ru/
        cultureKey ——— ru
        site_start ——— 2
        site_url ——— mysite.com/ru/

        Current .htaccess file:
        Options +FollowSymLinks
        
        RewriteEngine On
        RewriteBase /
        
        RewriteCond %{HTTP_HOST} .
        RewriteCond %{HTTP_HOST} !^mysite\.com [NC]
        RewriteRule (.*) http://mysite.com/$1 [R=301,L]
        
        # The Friendly URLs part
        RewriteCond %{QUERY_STRING} !cultureKey=(en|ru) [NC]
        RewriteRule ^$ en/ [R=301,L]
        
        RewriteCond %{REQUEST_URI} (en|ru)$
        RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
        
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(ru|en)/favicon\.ico$ favicon.ico [L,R=301]
        
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(ru|en)/assets/(.*)$ assets/$2 [L,R=301]
        
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(ru|en)/(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]


        Gateway plugin (actually the simplest one):
        if($modx->context->get('key') != "mgr")
        {
        	$cultureKey = $_GET["cultureKey"];
        	switch($cultureKey)
        	{
        		case 'ru':
        			$modx->switchContext('russian');
        		break;
        
        		case 'en':
        		default:
        			// by default, don't do anything
        			$modx->switchContext('web');
        		break;
        	}
        }
          • 37377
          • 64 Posts
          You could simplify your Gateway plugin if you plan on expanding the number of contexts

          if($modx->context->get('key') != "mgr"){
              $cultureKey = $_GET["cultureKey"];
              switch($cultureKey){
                  case 'en':
           		$modx->switchContext('web');
                  	break;
                  default:
                     	$modx->switchContext($cultureKey);
          		break;
              }
          }