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

    I’m trying to setup a multilingual website and i’ve got a problem with FirstChildRedirect.

    I’m using one context for each language: fr and en.
    On each context, I’ve set up differents parameters. Here is the configuration for the “en” context:
    base_url -> {base_url}en/
    site_url -> {site_url}en/
    cultureKey -> en
    site_start -> 1


    and the “fr” context :
    base_url -> {base_url}fr/
    site_url -> {site_url}fr/
    cultureKey -> fr
    site_start -> 2


    Then, I’ve added the plugin available in this thread: http://modxcms.com/forums/index.php/topic,51346.msg298387.html#msg298387
    <?php
        $pieces = explode('/', trim($_REQUEST[$modx->getOption('request_param_alias', null, 'q')], '/'), 2);
        if (count($pieces) > 0) {
            switch ($pieces[0]) {
                case 'en':
                    if (isset($pieces[1])) {
                        $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];
                    } else {
                        $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = '';
                    }
                    $modx->switchContext('en');
                break;
                case 'fr':
                    if (isset($pieces[1])) {
                        $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = $pieces[1];
                    } else {
                        $_REQUEST[$modx->getOption('request_param_alias', null, 'q')] = '';
                    }
                    $modx->switchContext('fr');
                break;
                default:
                break;
            }
        }
    ?>
    


    The plugin is loaded on the OnHandleRequest event.

    Finally, i’ve changed the index.php file in order to load the “fr” context by default:
    $modx->initialize('fr');


    Everything is working fine, except for the FirstChildRedirect snippet which isn’t working.

    Each parent document is associated with a template with the following code:
    [[!FirstChildRedirect? &sortDir=`ASC`]]


    When i’m clicking on a parent document, the browser returns me a 310 error:
    Erreur 310 (net::ERR_TOO_MANY_REDIRECTS)

    Is there something that i’m missing ? What should i do ?
    On the whole, is the entire configuration ok ?

    My server: MODx Revo 2.0.4, PHP 5.3.3, MySQL 5.1.39-1

    Thanks in advance.
      Intégrateur web freelance
      • 5340
      • 1,624 Posts
      When i’m clicking on a parent document, the browser returns me a 310 error:
      Erreur 310 (net::ERR_TOO_MANY_REDIRECTS)

      Try excluding the current page from being redirected more than once.
      I don’t have time to test code but maybe you have the skills to do it yourself.
        • 34001
        • 428 Posts
        Quote from: cipa at Nov 24, 2010, 03:08 PM

        When i’m clicking on a parent document, the browser returns me a 310 error:
        Erreur 310 (net::ERR_TOO_MANY_REDIRECTS)

        Try excluding the current page from being redirected more than once.
        I don’t have time to test code but maybe you have the skills to do it yourself.


        Thanks cipa. You mean in the FirstChildRedirect snippet itself ?
        Unfortunately, I’m not really skilled in PHP but still I will try. smiley
          Intégrateur web freelance
          • 34001
          • 428 Posts
          Ok, i’ve replaced FirstChildRedirect with a simpler snippet (11 is the ID of the child document):
          $url = $modx->makeUrl(11);
          return $modx->sendRedirect($url);​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
          

          It doesn’t work either.
          So, i’m quite sure that something in my whole configuration is not fine. But I don’t see what...
            Intégrateur web freelance
          • Change it to this and try it again:
            <?php
            $absoluteUrl = $modx->makeUrl(11, '', '', 'full');
            return $modx->sendRedirect($absoluteUrl);
            ?>
              • 34001
              • 428 Posts
              Thanks Jason.
              Unfortunately, the problem persists. I’ve tried the same snippet with another installation (with a simple web context) and everything is fine.

              Maybe we have found a bug ? rolleyes

              (if you need an access on my installation, don’t hesitate to tell me)
                Intégrateur web freelance
                • 5340
                • 1,624 Posts
                Is the code executed on both pages: parent and child?
                  • 34001
                  • 428 Posts
                  Quote from: cipa at Nov 24, 2010, 11:03 PM

                  Is the code executed on both pages: parent and child?
                  Nope... just the parent.
                    Intégrateur web freelance
                  • Look at the URL that is being generated; instead of doing the redirect, just output it. What does it return?
                      • 34001
                      • 428 Posts
                      Quote from: OpenGeek at Nov 25, 2010, 03:06 PM

                      Look at the URL that is being generated; instead of doing the redirect, just output it. What does it return?
                      The generated URL is the URL of the parent document. For example: http://example.com/fr/test/ ("test" is the alias of the parent document).

                      [edit] Sorry, I think I didn’t understand the question at first. I’ve created this snippet:
                      <?php
                      $absoluteUrl = $modx->makeUrl(11, '', '', 'full');
                        return $absoluteUrl;
                      

                      ... cleared the cache, but the same error is displayed...
                        Intégrateur web freelance