We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1535
    • 84 Posts
    Hi.

    Some time ago I moved a site from www.site.com/modx/ to the root www.site.com

    I did this in .htaccess with the line:
    redirect /modx/ http://www.site.com/


    This worked very well.

    Now I decided to turn on Friendly URL’s on the same site.

    This works well for all current URL’s, but the old redirect now fails.

    This old URL:
    http://www.site.com/modx/index.php?id=71


    Gets directed to:
    http://www.site.com/index.php?q=modx/index.php&id=71


    Which obviously fails.

    I have not been able to figure out how to use Friendly URL’s and also keep my old redirect.

    Here is the htaccess file:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
    redirect /modx/ http://www.site.com/


    Any assistance would be greatly appreciated.

    Cheers,

    Andreas
      • 21257 MODX Staff
      • 730 Posts
      I’m pretty sure you’ll want to send a 301 (permanent) redirect of anything in the /modx/ directory; if you just rewrote those URLs, bots would never realize that they have been moved.

      I would try:
      RewriteEngine On
      RewriteBase /
      
      RewriteRule ^modx\/(.*)$ /$1 [R=301,L]
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
      
      


      I hope I got the syntax right - rewrite rules can be finicky sometimes. The reason for the L at the end of the redirect is so that the server first returns the permanent redirect back to the client. Then when the client returns moments later with the request for the proper page, it will pass through to the MODx rerwrite rule.
      Your previous redirect line is no longer needed.

        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 1535
        • 84 Posts
        Sweet, thank yo very much netProphET!

        Seems to work just beautiful now, I just love this community smiley

        Cheers,

        Andreas