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

    I'm trying to rewrite a folder path in htaccess without much luck.

    I want to rewrite old folder path
    http://www.domain.com.au/library/online-marketing/
    to new folder path
    http://www.domain.com.au/library/strategy/
    This is what I've tried so far

    RewriteRule ^library\ online-marketing/(.*) /strategy/$1 [R=301,NC,L]
    RewriteRule ^library\ online-marketing/(.*) /strategy/$1 [R=301,NC,L]
    Redirect 301 /online-marketing/ http://www.domain.com.au/library/strategy
    RewriteRule ^online-marketing/(.*)$ /strategy/$1 [R=301,NC,L]


    (Not all at the same time.)

    Anyone see I'm going wrong?

    Thanks [ed. note: markg last edited this post 12 years, 2 months ago.]
      Content Creator and Copywriter
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Try
      RewriteRule ^library/online-marketing/(.*)$ library/strategy/$1 [R=301,NC,L]


      The ^ means "starts with"
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 18367
        • 834 Posts
        Quote from: sottwell at Jul 18, 2014, 10:46 PM
        Try
        RewriteRule ^library/online-marketing/(.*)$ library/strategy/$1 [R=301,NC,L]



        No joy I'm afraid.
          Content Creator and Copywriter
          • 3749
          • 24,544 Posts
          As Susan wrote, ^ matches the beginning of the line, so your rule won't execute unless the matched string is at the very beginning of the string being searched.

          What do you have at the top of the .htaccess file (Options +FollowSymLinks, Rewrite Engine, RewriteBase)?

          Do you have a RewriteCond statement (and if so, what is it)?

          Try using a full URL for the part after the space:

          RewriteRule ^library/online-marketing/(.*)$ http://yoursite.com/library/strategy/$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
            • 18367
            • 834 Posts
            Thanks Bob,

            yeah, sorry should have put the whole file in.

            Here it is below.

            RewriteEngine On
            RewriteBase /
            
            RewriteCond %{HTTP_HOST} ^mydomain\.com\.au [NC]
            RewriteCond %{HTTP_HOST} !^files\.mydomain\.com\.au [NC]
            RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [R=301,L]
            
            RewriteCond %{HTTP_HOST} ^www\.mydomain\.com\.au/index [NC]
            RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [R=301,L]
            
            RewriteCond %{THE_REQUEST} ^.*/index
            RewriteRule ^(.*)index$ http://www.mydomain.com.au/$1 [R=301,L]
            
            Redirect 301 /assets/images http://www.files.mydomain.com.au/images
            Redirect 301 /assets/files http://www.files.mydomain.com.au/files
            
            # The Friendly URLs part
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
            
            ExpiresActive On
            ExpiresByType image/gif A2592000
            ExpiresByType image/jpeg A2592000
            ExpiresByType image/png A2592000
            BrowserMatch "MSIE" brokenvary=1
            BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
            BrowserMatch "Opera" !brokenvary
            SetEnvIf brokenvary 1 force-no-vary
              Content Creator and Copywriter
              • 18367
              • 834 Posts
              I just don't understand why this redirect
              Redirect 301 /library/online-marketing http://www.markdeangarner.com.au/library/strategy
              isn't working when the other 301's for
              Redirect 301 /assets/images http://www.files.mydomain.com.au/images
              are.

              I must be missing something, but I can't see it.

              The returned url shows
              http://www.mydomain.com.au/library/strategy?q=library/online-marketing
              , so it seems to be reading it, it's just not finding the new folder.





                Content Creator and Copywriter
                • 3749
                • 24,544 Posts
                I've had trouble with Redirect 301 rules in MODX, I'm not sure why. You can use a RewriteRule instead.
                  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
                  • 18367
                  • 834 Posts
                  Bob,

                  yeah I was trying rewrites before, just tried again with
                  RewriteRule http://www.mydomain.com.au/library/online-marketing/(.*)$ 
                  
                  http://www.mydomain.com.au/library/strategy/$1 [R=301,NC,L]
                  and got exactly the same result
                  http://www.mydomain.com.au/library/strategy?q=library/online-marketing


                  So if I understand this correctly the query and the rewriting are occurring, but it's either just not processing the rewrite correctly or I've got an error in the rewrite somewhere.

                    Content Creator and Copywriter
                    • 3749
                    • 24,544 Posts
                    What is the result you want for the URL?
                      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
                      • 18367
                      • 834 Posts
                      Quote from: BobRay at Jul 22, 2014, 02:27 AM
                      What is the result you want for the URL?

                      http://www.mydomain.com.au/library/strategy


                      They're both folders by the way.
                        Content Creator and Copywriter