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

    I need to redirect some old pages to modx documents and I don’t know at all about mod_rewrite

    The old page was accessible here : h**p://www.globword.fr/commander-traduction/commande-traduction.php

    The new adress is : h**p://www.globword.fr/traduction-en-ligne/Commandez-une-traduction.html

    I’ve unsuccessfully tried to add some changes to .htaccess

    #here are the changes
    #permanent redirect
    
    Redirect 301 /commander-traduction/commande-traduction.php http://www.globword.fr/traduction-en-ligne/Commandez-une-traduction.html
    
    #end of the changes
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # If your MODx installation is in a subdirectory, change the following line to match the physical
    # path to the "root" of the site as follows:
    # RewriteRule ^(.*)$ /path/to/subdirectory/index.php?q=$1 [L,QSA]
    
    RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
    
    


    With these (i.e redirect function) changes when i’m calling the old page, the redirect doesn’t work and here is what i’ve got in the location bar:
    h**p://www.globword.fr/traduction-en-ligne/Commandez-une-traduction.html?q=commander-traduction/commande-traduction.php

    Does anybody know how I could solve this issue cause I’ve got to rename some of my pages and I’d like search engines be informed of theses changes

    Thx for your help smiley

      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 26439
      • 104 Posts
      Um.........

      Is there any reason why you can’t just do an old-fashioned 301 redirect?

      <?
      Header( "HTTP/1.1 301 Moved Permanently" );
      Header( "Location: http://www.new-url.com" );
      ?> 
      
      • Just add NC (which stands for no case) to the rewrite rule, so it looks something like this:

        RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA,NC]
        


        You could create weblinks or use $modx->sendRedirect() as well.
          • 11975
          • 2,542 Posts
          Sorry for non answering before but I was far from my computer

          Thx for your proposal I will give a try and let You know.

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 30223
            • 1,010 Posts
            I’ve used Redirect and rewriteRule several times before but have never encountered this so I just had to try this for myself. Same result! How odd. When I’ve used a similar combination I actually had the Redirect in apache’s configuration file (httpd.conf in my case) instead of in .htaccess. I tried this again and the redirection works as intended. So for some reason Redirect acts differently when placed in htaccess

            I see 2 solutions to your problem.


            • Place the Redirect in apache’s config.
            • Add rewriteRules that will do the redirects for you.

            The latter can be achieved like this:
            
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            
            # If your MODx installation is in a subdirectory, change the following line to match the physical
            # path to the "root" of the site as follows:
            # RewriteRule ^(.*)$ /path/to/subdirectory/index.php?q=$1 [L,QSA]
            
            # Added rule for redirect
            # The R=301 will force an external redirect with the 301 reply
            # The L flag will skip further rewriteRules
            # Use the NE (No Escape) flag to keep # hash (and other symbols) in the uri intact
            RewriteRule ^commander-traduction/commande-traduction.php	/traduction-en-ligne/Commandez-une-traduction.html [L,NE,R=301] 
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,PT]
            
            


            Edit: Oh, and be aware that you need to strip the first / from the url you want to redirect! In htaccess files the rewrite engine ".. the per-directory prefix (which always is the same for a specific directory!) is automatically removed for the pattern.." (from apache manual)

            So ^/commander-traduction/commande-traduction.php will not work. It needs to be ^commander-traduction/commande-traduction.php.
              • 11975
              • 2,542 Posts
              Thx Tobyl for your help but it doesn’t work  undecided

              I’ve copied and pasted your rewrite rules but the server send me back an internal error.

              I’ve also followed opengeek advice but it fails too.

              RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA,NC]
              


              I don’t know how I could fix this and obtain a 301 response header for my old pages.
              I need to simplify aliases of modx documents.
              Should I duplicate content and insert in old pages a snippet with sendRedirect to be sure of the HTTP-HEADER.

              Any advice is welcome smiley


              :-)


                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 30223
                • 1,010 Posts
                Hmm,works for me,... although I noticed that my homepage now produces a 404 error. undecided
                I’ll have to have another think about this, but not until I’ve had some sleep. Hopefully someone will have come up with the right answer before then.

                Good luck
                • Quote from: TobyL at Jun 04, 2006, 03:44 PM

                  Hmm,works for me,... although I noticed that my homepage now produces a 404 error. undecided
                  I’ll have to have another think about this, but not until I’ve had some sleep. Hopefully someone will have come up with the right answer before then.

                  Good luck

                  Re: 404 error: make sure your error page is not configured the same as your start page in your site configuration.