We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26388
    • 103 Posts
    We’ve migrated a site recently that had previously been in a cold fusion environment. We moved it to our service and rebuilt the site into modx. Now, for the search engines we’ve put in redirects like so:

    Redirect 301 /find_ranch.cfm http://www.coloradoranch.com/find-a-ranch.php


    However, if you try one of the old links either directly or through a google search, this is the result:

    http://www.coloradoranch.com/find-a-ranch.php?q=find_ranch.cfm

    Consequently, it’s not actually redirecting to the proper page and due to the resulting URL, it defaults to the home page of the site. Now, looking in the .htaccess file the rewrite rule looks like this:

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


    This is the ’stock’ .htaccess file supplied with modx. What do I need to adjust here? My redirects or the rewrite rule? And how should one or the other get adjusted?
      • 27708 MODX Staff
      • 2,502 Posts
      You should be able to make this work. The redirect should be before the rewrite in your .htaccess file. You have to request the URL to then have the .htaccess tell Apache where it is.

      It sounds like it could also be because you have multiple .htaccess files? Is this correct? Can you post your whole .htaccess file (please keep your private stuff private though)?
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 26388
        • 103 Posts
        Quote from: smashingred at Dec 27, 2007, 10:20 PM

        You should be able to make this work. The redirect should be before the rewrite in your .htaccess file. You have to request the URL to then have the .htaccess tell Apache where it is.

        It sounds like it could also be because you have multiple .htaccess files? Is this correct? Can you post your whole .htaccess file (please keep your private stuff private though)?

        Nope, just one .htaccess file. I did try placing the redirects above the rewrite rules and that didn’t work either. So, I’ve just created rewrite rules instead of redirects - placed them above the modx rewrite rule for the friendly urls - and it’s working now. Although not an ideal solution but in this case it will work fine.

        Like so:
        RewriteRule about_ranch.cfm http://www.coloradoranch.com/learn-about-ranches.php [L,NC,R=301]


          • 27708 MODX Staff
          • 2,502 Posts
          I am not sure why it didn’t work? I am not a Apache .htaccess wizard by any stretch of the imagination so I might keep looking. The friendly urls rewrite rule that MODx uses is fairly common so there should be examples of redirects working with redirects. Some versions of Apache I have had trouble using numeric redirects so ended up using keywords (not sure why this works over the numeric).

          Best of luck to you.

          Jay
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub