We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3004
    • 21 Posts
    We are using friendly URLs, with an .htaccess file as follows:

    
    # MODx supports friendly URLs via this .htaccess file. In order to use it, you must change the
    # file name from ht.access to .htaccess. If you don't want to use friendly URLs, you can comment
    # the three Rewrite directives out with pound signs (like the beginning of this line).
    #
    # Make sure RewriteBase points to the directory where you installed MODx.
    # E.g., "/" if your installation is in your root web documents directory (it comes this way by
    # default) or "/MODx" if your installation is in a MODx subdirectory, per the comments below. You
    # must serve web pages via Apache with mod_rewrite to be able to use this functionality.
    #
    # The last two blocks of rules at the bottom of this .htaccess file address anamolies with IE
    # for Windows PCs and the way in which it caches images, which causes a distracting flicker in
    # background images when links are hovered on the page.
    #
    # The output compression directives immediately below serve to speed up delivery of web pages,
    # and may also be optionally commented out.
    
    #php_flag zlib.output_compression On
    #php_value zlib.output_compression_level 5
    
    # Rewrite directives here for SEF (Search Engine Friendly) URLs
    
    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]
    
    # This following two sections stops screen flicker in IE on rollovers (Bad IE Win, Bad!).
    # Comment these sections out if you do not need them. They can result in having to force reload
    # pages when developing sites and changing images frequently to see your changes.
    
    #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
    
    
    


    Some of our URLs have changed, and I need to include a 301 redirect pointing to the new pages for the search engines. Including a line such as

    redirect 301 /oldfilename http://www.domain.com/newfilename


    returns a url as follows

    http://www.domain.com/newfilename?q=oldfilename


    which corresponds to the rewrite rule in the .htaccess file. I’ve done some looking but haven’t been able to find out how to get around this in the documentation or the forums. Any suggestions?

    Thanks a lot,

    Aaron
      • 22303 MODX Staff
      • 10,725 Posts
      Why not create web links to represent the old aliases?
        • 30223
        • 1,010 Posts
        A weblink would redirect allright but it wouldn’t alert a search engine of the fact that they shouldn’t keep the old url in teh index but instead use teh new url in the future.

        Come to think of it, I would find it a very usefull addition if you could set/insert a response header with weblinks. How doable would that be?
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: TobyL at Oct 26, 2006, 08:57 PM

          A weblink would redirect allright but it wouldn’t alert a search engine of the fact that they shouldn’t keep the old url in teh index but instead use teh new url in the future.

          Come to think of it, I would find it a very usefull addition if you could set/insert a response header with weblinks. How doable would that be?
          It’s actually very easy, and I have actually added a new parameter to sendRedirect in the 0.9.7 branch, so you can set the header response to any appropriate redirect response. I’ll port that back to the current version and see if we can’t easily add the ability to select at from any 3xx headers that might be appropriate when creating/editing weblinks.
            • 30223
            • 1,010 Posts
            Quote from: OpenGeek at Oct 26, 2006, 09:06 PM

            It’s actually very easy, and I have actually added a new parameter to sendRedirect in the 0.9.7 branch, so you can set the header response to any appropriate redirect response. I’ll port that back to the current version and see if we can’t easily add the ability to select at from any 3xx headers that might be appropriate when creating/editing weblinks.

            Excellent!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              A while back I added a hack allowing weblinks to simply use a document ID, and the hack to the parser would use makeUrl on it before the sendRedirect. Then I added the cute touch of a folder icon to behave like the "select parent" folder icon, so you could click on the document tree to get the id.

              Then somebody came up with the otherwise excellent idea of having the Wayfinder display a weblink’s content as the link instead of the ID of the weblink itself...ouch! tongue

              So it looks like I’ll (or somebody, anyway...) have to get to work and make that click-on-the-document-in-the-document-tree do a quick makeUrl on the ID selected, and load the url into the form field.
                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
                • 3004
                • 21 Posts
                It’s actually very easy, and I have actually added a new parameter to sendRedirect in the 0.9.7 branch, so you can set the header response to any appropriate redirect response. I’ll port that back to the current version and see if we can’t easily add the ability to select at from any 3xx headers that might be appropriate when creating/editing weblinks.

                Sorry, but I guess I need a little more explanation. I do need a redirect method that will alert the search engines of the new address--the main reason I’m changing urls is for SEO. In the above you seem to say that it’s easy to send a header response code with a weblink, but I gather that you mean it would be easy to add this function into Modx--not that it’s easy to do within the current version. We’re running 9.2.1. Is there a way to do what I need to do in that version?
                  • 28069
                  • 1 Posts
                  Has anyone found a solution to this? We’re experiencing a very similar issue.

                  Thanks!
                    • 33372
                    • 1,611 Posts
                    Indeed it would be great to have that code so that we can send appropriate 301 redirects from weblinks in 0.9.2 installations.

                    Regular Apache redirects in .htaccess do indeed return a broken URL (that doesn’t forward), but you can use rewrite rules just above the MODx ones like so:

                    RewriteRule oldpage.html http://www.yourdomain.com/newpage.html [L,NC,R=301]


                    Just add those above these lines:
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteCond %{REQUEST_FILENAME} !-d


                    This will supercede any documents created within MODx (possibly leading to confusion if people later try to create documents with your redirected aliases), so it’s not an ideal solution but it does work.

                      "Things are not what they appear to be; nor are they otherwise." - Buddha

                      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

                      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                      • 1209
                      • 49 Posts
                      Hello.

                      In my case the "old" url contains ? sign. I am migrating from some old CMS.
                      So I need to redirect
                      [tt] modules.php?name=Courses[/tt] to [tt]http://my.site.com/courses[/tt]

                      RewriteRule ^modules\.php\?name=Courses$ http://my.site.com/courses [R=301,L]


                      This code doesn’t do the job, because the ?-part of the url is not accepted by the rewrite_mod. The rewriter seems to not see that part of the url. If I write

                      [tt]RewriteRule ^modules\.php$ http://my.site.com/courses [R=301,L][/tt]

                      then the redirection actually drops me to the url [tt]/courses?name=Courses[/tt] keeping the second part intact. But I don’t need that. My task is to redirect from the full url with the ?-part.