We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    Try something like:
    RewriteCond %{QUERY_STRING} ^name=Courses$
    RewriteRule ^/?modules\.php$ http://my.site.com/courses [R=301,L]
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 1209
      • 49 Posts
      Thanks!
      That’s better.
      The redirection works now. But in result I still get [tt]/courses?name=Courses[/tt]. For me it is ok, I see right information on the page. But I wouldn’t like to have that ?-part in the resulting url actually. Because I don’t want the page to be available at [tt]/courses[/tt] and [tt]/courses?name=Courses[/tt] for the SEO issues.
        • 33372
        • 1,611 Posts
        How about:
        RewriteCond %{QUERY_STRING} ^(.+)\name=Courses$
        RewriteRule ^/?modules\.php$ http://my.site.com/courses?%1 [R=301,L]
        
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
          • 1209
          • 49 Posts
          I just had to remove (.+) and everything works as expected. That %1 makes the job. (.*) could be used as well. But with undefined %1 the trick works as well.

          I have another question. Is it possible to store the redirection information not in the .htaccess, but in TVs for example.

          I want to use the TV ’oldUrl’ to store the old URL.
          And I want to make a plugin that would be started OnPageNotFound.
          The plugin will get the current not existing URL, find it in the TV table, get the docid and sendRedirect.
          I am not quite sure that I do it right, but here is the code.

          $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);
          
            • 33372
            • 1,611 Posts
            That certainly looks like it has potential. I’m not sure about your $current var though. Shouldn’t you be looking for $_GET[’name’]?

            You know, if I were you I probably wouldn’t even do these redirects in MODx or .htaccess. Why not just create a new modules.php file and do the redirects in there? It would probably be a lot easier.

            Just make it something like:


            
            switch ($_GET['name']) {
            case 'Courses':
               $goTo='courses'
               break;
            case 'Whatever':
               $goTo='whatever'
               break;
            case 'something-else':
               $goTo='something/else'
               break;
            default:
               $goTo='error'
            }
            
            $goTo='http://my.site.com/'.$goTo;
            
            header('HTTP/1.1 301 Moved Permanently');
            header("Location: $goTo");
            exit;
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn't very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 1209
              • 49 Posts
              here is the Dev thread concerning this plugin.
              http://modxcms.com/forums/index.php/topic,13134.0.html
                • 4215
                • 5 Posts
                Hi,
                I have the same problem.
                I moved an old static site to MODx.
                Some of the old pages need a 301 redirect to the new ones.
                I didn’t find the solution here in the forum, but I did found a solution so here it is:

                Just above RewriteCond %{REQUEST_FILENAME} !-f add this:

                RewriteRule ^old/URL/path$ http://yourdomain.com/new/path [R=301,L]

                You can find more information here: http://www.somacon.com/p145.php and here: http://drupal.org/node/38960

                Hope this helps
                  • 3749
                  • 24,544 Posts
                  This is a very old thread, but for anyone who finds it, there's now a much easier method.

                  In any version of MODX Revolution from 2.2.5 on, you can enter the response code on the "Settings" tab when editing a Weblink in the Manager. The following code will usually be filled in for you, and is most likely what you want:

                  HTTP/1.1 301 Moved Permanently
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting