We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18646
    • 106 Posts
    I found this thread: http://modxcms.com/forums/index.php/topic,15811.msg242559.html
    It explains how to force the FirstChildRedirect snippet force a 301 redirect instead of the 302 it produces by default.

    The syntax change that sirlancelot suggests is what I’m trying to do, but it breaks the MODx manager. I get a page reset message everytime I try it. I’m using FirstChildRedirect 1.1.

    Can anyone help? Thanks!

    Regards,
    Matt
      • 7231
      • 4,205 Posts
      Odd, it shouldnt have an effect on the manager, just the front end. Are you getting an error message?
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 18646
        • 106 Posts
        Not getting an syntax error message. What i get is this: http://www.screen-shot.net/ss/302183698124698887.png
        Then, when I go back to look at the FirstChildRedirect snippet, most of the php is gone. I have to re-input the orginal snippet, and it saves without an issue.

        I can produce the same problem running MODx 0.9.6.1 and 0.9.6.3

        Regards,
        Matt
          • 7231
          • 4,205 Posts
          Can you post the code you have from the snippet. May find a clue in the code. Are you using sirlancelots modification from the post you mentioned?
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 18646
            • 106 Posts
            Sure, so here’s the code from my version of the snippet:

            <?php
            /*
             * @name FirstChildRedirect
             * @author Jason Coward <[email protected]>
             * @modified-by Ryan Thrash <[email protected]>
             * @license Public Domain
             * @version 1.0
             * 
             * This snippet redirects to the first child document of a folder in which this
             * snippet is included within the content (e.g. [!FirstChildRedirect!]).  This
             * allows MODx folders to emulate the behavior of real folders since MODx
             * usually treats folders as actual documents with their own content.
             * 
             * Modified to make Doc ID a required parameter... now defaults to the current 
             * Page/Folder you call the snippet from.
             * 
             * &docid=`12` 
             * Use the docid parameter to have this snippet redirect to the
             * first child document of the specified document.
             */
            
            $docid = (isset($docid))? $docid: $modx->documentIdentifier;
            
            $children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
            if (!$children === false) {
                $firstChild= $children[0];
                $firstChildUrl= $modx->makeUrl($firstChild['id']);
            } else {
                $firstChildUrl= $modx->makeUrl($modx->config['site_start']);
            }
            return $modx->sendRedirect($firstChildUrl);
            ?>
            


            And I’m following sirlancelots modification from the post. That when i hit save, everything falls apart. Thanks for your help dev_cw!

            Regards,
            Matt
              • 7231
              • 4,205 Posts
              Matt, I tested this with the edit from the other post and had no problems. Here is the code i used, maybe you have a typo or something happening.

              <?php
              /*
               * @name FirstChildRedirect
               * @author Jason Coward <[email protected]>
               * @modified-by Ryan Thrash <[email protected]>
               * @license Public Domain
               * @version 1.0
               * 
               * This snippet redirects to the first child document of a folder in which this
               * snippet is included within the content (e.g. [!FirstChildRedirect!]).  This
               * allows MODx folders to emulate the behavior of real folders since MODx
               * usually treats folders as actual documents with their own content.
               * 
               * Modified to make Doc ID a required parameter... now defaults to the current 
               * Page/Folder you call the snippet from.
               * 
               * &docid=`12` 
               * Use the docid parameter to have this snippet redirect to the
               * first child document of the specified document.
               */
              
              $docid = (isset($docid))? $docid: $modx->documentIdentifier;
              
              $children= $modx->getActiveChildren($docid, 'menuindex', 'ASC');
              if (!$children === false) {
                  $firstChild= $children[0];
                  $firstChildUrl= $modx->makeUrl($firstChild['id']);
              } else {
                  $firstChildUrl= $modx->makeUrl($modx->config['site_start']);
              }
              // return $modx->sendRedirect($firstChildUrl);
              return $modx->sendRedirect($firstChildUrl, 0, '', 'HTTP/1.0 301 Moved Permanently');
              ?>
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 18646
                • 106 Posts
                No dice. I get the page was reset message. Those changes will not stick. So odd, it definately has something to do with that last line:

                return $modx->sendRedirect($firstChildUrl,0,'','HTTP/1.0 301 Moved Permanently');


                For some reason, the manager fails on that line. If it helps any, I’m running PHP Version 5.1.6

                Regards,
                Matt
                  • 7231
                  • 4,205 Posts
                  Maybe a cache issue? If you can login to the manager clear the cache and see if it helps.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don&#39;t know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 18646
                    • 106 Posts
                    Nope, that doesn’t work either. Something just occurred to me. Rather then relying on the MODx manager, is there a way I can adjust this snippet either via FTP or using SSH? Maybe that would force the change to stick?

                    Regards,
                    Matt
                      • 7231
                      • 4,205 Posts
                      you can edit the snippet code in our database directly. They are in the table named modx_site_snippets (if you are using the modx_ prefix).
                        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                        Something is happening here, but you don&#39;t know what it is.
                        Do you, Mr. Jones? - [bob dylan]