We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51347
    • 82 Posts
    Hi guys,

    i have problem with the alias. I cant open sites with alias that begin with "en" "de" "ru" "es" like example.com/design or example.com/running..


    I used this tutorial: https://anyscreensize.com/blog/modx-multilingual

    here i found the same problem, but i cant find the reason: https://github.com/mikrobi/babel/issues/112


    MODx Revo 2.5.7
    Babel 3.0.0-pl
    PHP 5.56
    MySQL 5.6.19


    I tried this getaway plugins:

    <?php
    if($modx->context->get('key') != "mgr"){
            //grab the current domain from the http_host option
            switch ($modx->getOption('http_host')) {
                case 'en':
                    //switch the context
                    $modx->switchContext('Englisch');
                    //set the cultureKey
                    $modx->setOption('cultureKey', 'en');
                    break;
                case 'ru':
                    //switch the context
                    $modx->switchContext('Russisch');
                    //set the cultureKey
                    $modx->setOption('cultureKey', 'ru');
                    break;
                default:
                case 'e':
                    //switch the context
                    $modx->switchContext('Spanisch');
                    //set the cultureKey
                    $modx->setOption('cultureKey', 'es');
                    break;
                default:
                    // Set the default language/context here
                    $modx->switchContext('web');
                    $modx->setOption('cultureKey', 'de');
                    break;
            }
        }


    and

    <?php
    if($modx->context->get('key') != "mgr") {
                /* Определяем текущий язык в cultureKey */
                switch ($_REQUEST['cultureKey']) {
                /* Переключаем контекст */
                case 'en':
                $modx->switchContext('Englisch');
                break;
                case 'ru':
                $modx->switchContext('Russisch');
                break;
                case 'es':
                $modx->switchContext('Spanisch');
                break;
                /* Устанавливаем контекст по умолчанию */
                default:
                $modx->switchContext('web');
                break;
                }
    /* Очищаем GET-параметр чтобы не допустить появлении ссылки вида cultureKey=xy при генерации URL других компонентов */
    unset($_GET['cultureKey']);
    }



    I read this topic allready, but it doesnt help: https://forums.modx.com/thread/87228/babel---alias-confused-with-culture-key-on-url

    Please help! [ed. note: joe-petts last edited this post 6 years, 9 months ago.]
      • 5430
      • 247 Posts
      You might try something like LangRouter (https://modx.com/extras/package/langrouter) or XRouting instead of your gateway plugin, but I suspect the problem you're having is this line in your htaccess file:
      RewriteRule ^(en|nl|de)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]

      I'm not certain of the regex in this context, but I think the issue might be the question marks. I've been using NGINX for a while now and am pretty rusty with Apache rewrites, so somebody correct me if I'm wrong here but you should be able to use something like:
      RewriteRule ^(en|nl|de)/(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
        • 51347
        • 82 Posts
        Thank you for answer!


        If i change my "?/?" to "/", i cant load any Site.

        I try to use XRouting too, but i get the same problem. Everything works, but not sites like example.com/design or example.com/running..


        I think something is wrong with the .htaccess?


        Here ist my .htaccess:


        RewriteEngine On
        RewriteEngine On
        RewriteBase /
        
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(de|en|ru|es)/favicon.ico$ favicon.ico [L,QSA]
        
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(de|en|ru|es)/assets(.*)$ assets$2 [L,QSA]
        
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(de|en|ru|es)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
        
        # The Friendly URLs part
        # RewriteCond %{REQUEST_FILENAME} !-f
        # RewriteCond %{REQUEST_FILENAME} !-d
        # RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
        
        • Try to add this before favicon:

          # The Friendly URLs part
          # redirect original domain.name to domain.name/defaultLang
          RewriteCond %{HTTP_HOST} .
          RewriteRule ^$ en/ [R=301,L]
          
          #https://github.com/chsmedien/XRouting/issues/19#issuecomment-173992718
          RewriteCond %{REQUEST_URI} ^/(en|de|id|in|jp|nl|ru|th|zh)$
          RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
          


          edit this part (en|de|id|in|jp|nl|ru|th|zh) using yours
            Rico
            Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
            MODx is great, but knowing how to use it well makes it perfect!

            www.virtudraft.com

            Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

            Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

            Maintainter/contributor of Babel

            Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
            • 51347
            • 82 Posts
            Thanks for Help goldsky, but it doesnt help. I get everytime the error-page...
            • I used a modified Xrouting plugin
              https://gist.github.com/goldsky/e926167132e227e2f10f

              PS: make sure you only have 1 (one) routing plugin enabled
                Rico
                Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                MODx is great, but knowing how to use it well makes it perfect!

                www.virtudraft.com

                Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                Maintainter/contributor of Babel

                Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                • 51347
                • 82 Posts
                Thanks,

                i try Xrouting again and hope, that works!