We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1209
    • 49 Posts
    History:

    I had to migrate a website from the old phpnuke cms to MODx.
    Page urls in the old nuke were terrible: [tt]/module.php?name=Pages&paremeters=123[/tt] and so on.

    On the MODx all URLs are friendly AND different from the original.

    I have wrote the Legacy Redirector plugin to catch the calls to the old address of the page and send the 301-redirect to the new friendly URL. The old address [tt]/module.php.........[/tt] should be written in a TV "oldURI" for each redirected document.

    OnPageNotFound:
    
    <?php
    $TVname = 'oldURI';
    
    $current = $_SERVER["REQUEST_URI"];
    $tmplvars = $modx->getFullTableName("site_tmplvars");
    $contentvalues = $modx->getFullTableName("site_tmplvar_contentvalues");
    $docQuery = $modx->db->query("SELECT contentid FROM $tmplvars INNER JOIN $contentvalues ON $tmplvars.id = $contentvalues.tmplvarid WHERE $tmplvars.name = '$TVname' AND $contentvalues.value = '$current'");
    if ($modx->db->getRecordCount($docQuery) > 0) {
      $docRow = $modx->db->getRow($docQuery);
      $id = $docRow['contentid'];
      $url = $modx->makeUrl($id, '', '', 'full');
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: $url");
      break; 
    }
    
      • 33337
      • 3,975 Posts
      Zaigham (aka zi) Reply #2, 19 years ago
      Cool plugin almays!

      Thanks for sharing.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 2954
        • 40 Posts
        In the TV if you don’t want to proceed every page with a "/" just replace the $current variable set with:

        $current = substr($_SERVER["REQUEST_URI"],1);

        I entered all my old URI’s into the pages without the slash and this took care of it.
          • 24330
          • 28 Posts
          This plugin seems really helpful - thanks almays!  grin Now if I could only get it to actually redirect and not show my 404 page... wink

          Below is what I did using MODx 0.9.6.1 - am I missing something?


          • Copied the plugin code here and then clicked to on New plugin in MODx.
          • Added the name Legacy Redirector into the Plugin name field
          • Added a description to the Description field
          • Pasted the code into the Plugin code textarea
          • Locked the plugin for admin editing only
          • Clicked the Configuration tab and selected a category for the new plugin
          • Clicked the System Events tab and checked the box for OnPageNotFound
          • Saved the plugin
          • Clicked the Template Variables tab and then the New Template Variable link
          • Entered the text oldURI into the Variable Name field
          • Added a caption and a description into the corresponding fields
          • Checked the boxes for the templates I wanted to have access to the new variable
          • Saved the new Template Variable
          • Opened a page that has an older page URI I want redirected to it
          • Scrolled down to the field for the new Template Variable
          • Entered the text /oldname.html into the field
          • Saved the page
          • Entered the text http://domain.com/oldname.html into my browser to test the redirect
          • Result: my 404 page  :’(

          UPDATE:
          I just checked my System Events, and I’m getting the following error from the Legacy Redirector plugin:
          parse error, unexpected '<'
          Parse error: parse error, unexpected '<' in /home/content/p/o/m/pomassage/html/manager/includes/document.parser.class.inc.php(745) : eval()'d code on line 1


          So, I simply deleted the
          <?php

          from the plugin code supplied by Alexey above, and all is working as expected.
            Rafael
            • 24330
            • 28 Posts
            I have another question:
            How can I modify the plugin code to allow more than one old URI to be entered into the Template Variable?
              Rafael
              • 1209
              • 49 Posts
              http://www.stanback.net/code/modx/virtual-aliases.html

              On that site another friend has published the better plugin, that covers the functionality of this one and allows to put several oldURIs.
                • 1564
                • 31 Posts
                Quote from: almays at Mar 17, 2008, 01:28 PM

                http://www.stanback.net/code/modx/virtual-aliases.html

                On that site another friend has published the better plugin, that covers the functionality of this one and allows to put several oldURIs.
                Thanks for the link and for the work.

                Everything is working for me I am just about to ask one thing.. How is it with processing a index.php with a string query? lets say.. "/index.php?menu=2&language=fr" ... is it possible to make a small mod that would enable 301 redirect of these index URLs? Unfortunately the old web site had all coded within a index.php and now I am fearing a SE penalty becase the old URL indexed do give 404 sad
                  MODx is way ahead... Thanks for your work!