We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17412
    • 270 Posts
    re: FirstChildRedirect - this produces a 302 re-direct. As far as I understand it - that’s not the most SEO-friendly re-direct. Is there a way to make this a 301 permananent re-direct?
      • 27376
      • 576 Posts
      Change the very last line of the snippet from:
      return $modx->sendRedirect($firstChildUrl);
      to
      return $modx->sendRedirect($firstChildUrl, 0, '', 'HTTP/1.0 301 Moved Permanently');
        • 17412
        • 270 Posts
        wow! nice one Sirlancelot.
        I wonder if it would it be worth updating the core firstchildredirect snippet to be a 301 considering the SEO-slant of Modx ?
          • 22303 MODX Staff
          • 10,725 Posts
          The other option, which may be preferable depending on your needs, is to use the new API method sendForward() rather than sendRedirect(). 301 redirects mean that the old URL is not the proper one anymore (moved permanently) and 302 means that it has moved temporarily and you should continue using the original URL requested to get to the resource. However, I think more appropriate for the purposes of emulating traditional web folder behavior would be to simply not redirect the URL at all and present the content of the first child at that location.

          Here is a quick modification of FirstChildRedirect that exemplifies this usage, which I will call FirstChildForward... (I have not tested this, but it should do the job)...

          <?php
          /**
           * @name FirstChildForward
           * @author Jason Coward <[email protected]>
           * @license Public Domain
           * @version 1.0
           * 
           * This snippet forwards 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 forward 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];
              $firstChildId= $firstChild['id'];
          } else {
              $modx->sendErrorPage();
          }
          return $modx->sendForward($firstChildId);
          ?>
            • 17412
            • 270 Posts
            double wow!!
            presenting the content of the first child at the parent location - does this mean that there would be two ways (2 x urls) of accessing the same content?

            I will install FirstChildForward and see what’s what.

            Many thanks Jason.
              • 1186
              • 202 Posts
              Hello, I’ve just tried FirstChildForward and it seems to work fine. Thanks !
              But I wonder if it really solves the potential SEO issue : Google doesn’t like pages with same contents, different urls, does it ?
                R
                • 22303 MODX Staff
                • 10,725 Posts
                This is a complex issue, and depends exactly how you decide to structure your site, but I think this link has the most sane advise I can find. http://www.searchenginejournal.com/should-urls-in-links-use-indexhtml/4434/

                The key points I take away are, referring to folders and an index page for the same content does not penalize you, though it may split your page rankings. And to avoid that problem, just make sure the links are built consistently (i.e. don’t refer to it both ways in your content) or use 301 redirects to make sure you avoid splitting your page ranks. If you use the altered FirstChildRedirect that uses 301 redirects, you can solve that easily enough when someone accesses the folder. If you want the folder to be the URL however, you would need to combine the forwarding behavior with redirect behavior on the index pages themselves (i.e. redirect path/index.html to path/ with a 301 either with a plugin, snippet, or mod_rewrite rules).

                I believe the SEO-Strict plugin addresses this more completely.
                  • 18646
                  • 106 Posts
                  This thread is exactly what I’ve been looking for, but the solution given by sirlancelot breaks my installation of MODx. The page doesn’t save, and when it reloads, most of the firstchildredirect code is missing. I’m using firstchildredirect 1.1. Any ideas? Thanks!

                  Regards,
                  Matt