We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29597 ☆ A M B ☆
    • 350 Posts
    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:
    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;
                }
            }
        }
    ?>
    

    This question has been answered by icebear. See the first response.

    [ed. note: ThaClown last edited this post 14 years, 10 months ago.]
      MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
      DESIGNfromWITHIN, MPThemes and Any Screen Size
      Follow me on Twitter | Read my blog | My code on GitHub
    • discuss.answer
      • 36756
      • 7 Posts
      What helped for me was:

      1. Disable language detection in the .htaccess (lines 12-15)
      2. Remove all "en|" entries in the .htaccess as this is the default language
      3. Context settings

      web

      base_url: /
      cultureKey: en
      site_start: 1
      site_url: http://mysite.com/

      Nederlands

      base_url: /nl/
      cultureKey: nl
      site_start: 11
      site_url: http://mysite.com/nl/

      Deutsch

      base_url: /de/
      cultureKey: de
      site_start: 22
      site_url: http://mysite.com/de/

      Gateway-Plugin
      <?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('nl');
              break;
      		
      	case 'de':
              $modx->switchContext('de');
              break;
       
      	default:
              // nothing because web is default
              break;
          }
      	$modx->setPlaceholder('context_key', $modx->context->get( 'key' ));
          }
      }
      


      4. Install Babel after you did all the settings. [ed. note: icebear last edited this post 14 years, 10 months ago.]
        • 29597 ☆ A M B ☆
        • 350 Posts
        You sir, Are my personal hero now!

        My gateway plugin is a bit different but this works for me:
        <?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 'nl':
                  $modx->switchContext('Nederlands');
                  $modx->setOption('cultureKey', 'nl');
                  break;
        
                case 'de':
                  $modx->switchContext('Deutch');
                  $modx->setOption('cultureKey', 'de');
                  break;
                  
                default:
                // nothing because web is default
                break;
        
              }
            }
          }
        
        [ed. note: ThaClown last edited this post 14 years, 10 months ago.]
          MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
          DESIGNfromWITHIN, MPThemes and Any Screen Size
          Follow me on Twitter | Read my blog | My code on GitHub