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

    I am running modx revo 2.2.14-pl and am trying to setup 301 re-directs for my new site (I thought it would be a lot easier). Basically I am running revo on a Windows server enviroment, configured via IIS and running .htaccess via helicon ape. Now my .htaccess file is fine as I have setup the re-write conditions and enabled g-zip without issue, I just cant seem to figure out 301 re-directs with revo. I have searched for this issue on google and have found many threads about it, I have tried the majority and still no joy.

    Please find a copy of my .htaccess file:

    # Helicon Ape version 3.1.0.135

    RewriteEngine On
    RewriteBase /

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

    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html [L,QSA]

    SetEnv gzip

    ExpiresActive On
    Header set Cache-Control public
    ExpiresByType image/.+ "access 15 days"
    ExpiresByType text/css "access 5 days"
    ExpiresByType application/x-javascript "access 5 days"
    ExpiresByType application/javascript "access 5 days"

    AuthType Basic
    AuthName "Password Protected Area"
    AuthUserFile .htpasswd
    Require valid-user

      • 3749
      • 24,544 Posts
      Can you give some examples of the before and after full URLs you want?
        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
        • 45929
        • 16 Posts
        Hi Bob,

        Yes they would be:

        Old url: http://www.mysite.com/my-link.php

        New url: http://www.mysite.com/my-link

        I also have directories setup on my old site

        Old url: http://www.mysite.com/directory-name

        New url: http://www.mysite.com/new-directory-name

        Thanks,
        Michael
          • 3749
          • 24,544 Posts
          Try this (put it at the top -- above the www and FURL rules):

          RewriteEngine on
          RewriteBase /
          
          
          #remove .php
          RewriteCond %{SCRIPT_FILENAME} !-f
          RewriteCond %{REQUEST_URI} ^(/.+)\.php$
          RewriteRule ^(.+)\.php$ %1 [R=301,L]
          
          #rewrite directory
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f    
          RewriteRule ^directory-name/(.*)$ /new-directory-name/$1 [R=301,NC,L]
            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
            • 45929
            • 16 Posts
            Hi Bob,

            Thanks for coming back to me again:

            I updated my .htacces and it now looks like the following:

            # Helicon Ape version 3.1.0.135
            
            RewriteEngine
             on
            RewriteBase /
            
            
            #remove .php
            RewriteCond %{SCRIPT_FILENAME} !-f
            RewriteCond %{REQUEST_URI} ^(/.+)\.php$
            RewriteRule ^(.+)\.php$ %1 [R=301,L]
            
            #rewrite directory
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME} !-f    
            RewriteRule ^directory-name/(.*)$ /new-directory-name/$1
             [R=301,NC,L]
            
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
            
            RewriteCond %{REQUEST_FILENAME}.html -f
            RewriteRule ^(.*)$ $1.html [L,QSA]
            
            SetEnv gzip
            
            ExpiresActive On
            Header set Cache-Control public
            ExpiresByType image/.+  "access 15 days"
            ExpiresByType text/css  "access 5 days"
            ExpiresByType application/x-javascript "access 5 days"
            ExpiresByType application/javascript "access 5 days"
            
            AuthType Basic
            AuthName "Password Protected Area"
            AuthUserFile .htpasswd
            Require valid-user
            


            is that correct?

            Anyway what I have doesn't work unfortunately.

            Thanks
            Michael
              • 3749
              • 24,544 Posts
              For this one, did you put the actual directory names in?

              RewriteRule ^directory-name/(.*)$ /new-directory-name/$1


              Also, try it this way:

              RewriteRule directory-name/(.*)$ new-directory-name/$1
                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
                • 45929
                • 16 Posts
                Hi Bob,

                Yes I added the directory names to the rewrite rule and it did not work, I also tried your alternative which does not work for me either.

                I have been able to setup re-directs for the old site on this server before/currently using web.config file, now I am using helicon ape / .htaccess I am having some difficulty getting it to work with the new modx site. Some of the old directories are becoming obsolete so it will be the basic request for those url's that I want to re-direct to a new url of my choice.

                I have 301 redirects setup fine with several other sites including wordpress sites that I am running off the same server.

                Thanks again,
                Michael
                  • 3749
                  • 24,544 Posts
                  I can't think of any reason why those wouldn't work, unless it's an nginx server or handles .htaccess rules in some strange way.

                  You could try commenting out the RewriteCond lines for those rules. Other than that, I'm afraid I don't have anything else to suggest.
                    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
                    • 45929
                    • 16 Posts
                    Hi Bob,

                    Thank's for your time, I have ended up going back to the IIS URL Rewrite module which is working for me.


                    I created a rewrite map:

                    		    
                    <rewriteMaps configSource="Web.RewriteMaps.config"/>
                      <rules>
                        <rule name="Old Page Redirects" stopProcessing="true">
                    	<match url=".*"/>
                    	  <conditions>
                    	    <add input="{OldPages:{REQUEST_URI}}" pattern="(.+)"/>
                    	  </conditions>
                    	  <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent"/>
                        </rule>
                    


                    and my re-direct config:

                    <rewriteMaps>
                      <rewriteMap name="OldPages">
                        <add key="/oldpage.aspx" value="/newpage.aspx" />			
                      </rewriteMap>
                    </rewriteMaps>
                    


                    Thanks for your help Bob,

                    Michael
                      • 3749
                      • 24,544 Posts
                      I'm glad you got it sorted. Thanks for reporting back. smiley
                        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