We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1209
    • 49 Posts
    The ready beta of the plugin is at
    http://modxcms.com/forums/index.php/topic,18526.0.html

    =======
    I am now busy with migrating one quite huge web-site from postnuke to modx.

    In the old nuke there was no Friendly URLs. But the Web-site is quite popular and well-indexed. There are a lot of links in the web that cite the site. The URLs in the modx realisation will be surely different from the old ones. Is the a way make some module or some intelligent TV trick that would allow to add the old url to each page so that the page would be either available at the old url as well, or some redirect would be implemented.

    I could put the old url to the TV, make some special 404 page that would get the original url, scan the TVs, locating the new address, and redirect via javascript to the actual new page. But that is too wrong. I’d like to use HTTP headers redirection or maybe something via Rewrite_mod. What would you recommend?
      • 18397
      • 3,250 Posts
      You could write a plugin that OnPageNotFound takes the current URL, searches the tv values table for it (of course where the tv name = the tv you created) and if found sends a 301 permanent redirect header with a location made with $modx->makeURL(ID of the document attached to the tv)
        • 1209
        • 49 Posts
        could you navigate me to some plugin tutorial and modx API?
          • 18397
          • 3,250 Posts
          See the Documentation @ modxcms.com/documentation
            • 1209
            • 49 Posts
            After an hour I came to such a code.
            It doesn’t work.
            What is wrong?
            It is my first modx plugin in fact.

            $TVname = 'oldUrl';
            
            $current = urldecode($_GET['effective_url']);
            
            $table = $modx->getFullTableName("site_tmplvars");
            $TVid = mysql_fetch_row($modx->db->select('id', $table, "name = $TVname"))['id'];
            $table = $modx->getFullTableName("site_tmplvar_contentvalues");
            $doc = mysql_fetch_row($modx->db->select('contentid', $table, "value=$current and tmplvarid=$TVid"))['contentid'];
            
            $url=$modx->makeUrl($doc);
            $modx->sendRedirect($url, 1);
            
              • 18397
              • 3,250 Posts
              $modx->db->select already returns all the rows found in an array per http://modxcms.com/dbapi-select.html. You shouldn’t need the mysql_fetch_row’s
                • 1209
                • 49 Posts
                After all seems that everything is about to work.
                I just can’t find the right way to get know the currently requested URL.
                [tt]$_SERVER[’PHP_SELF’][/tt] gives true [tt]index.php[/tt]
                  • 1209
                  • 49 Posts
                  Ok.

                  Here is the result

                  $TVname = 'oldURI';
                  
                  $current = $_SERVER["REQUEST_URI"];
                  
                  $table = $modx->getFullTableName("site_tmplvars");
                  $TVid = mysql_fetch_row($modx->db->select('id', $table, "name = '$TVname'"))['id'];
                  $table = $modx->getFullTableName("site_tmplvar_contentvalues");
                  $doc = mysql_fetch_row($modx->db->select('contentid', $table, "value='$current' and tmplvarid='$TVid'"))['contentid'];
                  
                  $url=$modx->makeUrl($doc);
                  $modx->sendRedirect($url, 1);
                  


                  I have to use [tt] mysql_fetch_row[/tt], because [tt]select[/tt] returns usual result resource.

                  But! It still doesn’t work.

                  How can I log some text to the modx system log for debugging?
                    • 18397
                    • 3,250 Posts
                    If you want to see what a variable is just use var_dump($varname);
                      • 1209
                      • 49 Posts
                      And where does it put the results?

                      Hmmmmm...

                      Very fuzzy thing.

                      This discussion is closed to further replies. Keep calm and carry on.