We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4626
    • 57 Posts
    Ok, maybe now I’ve got it...

    Try this:
    RewriteCond %{REQUEST_URI} ^.*\.html$
    RewriteRule ^(.*)\.html$ http://domain/$1 [R,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    instead of:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
      • 24278
      • 165 Posts
      Superb. It works. Thanks a bunch carl.

      Ok, one question...

      I have one (physical) folder (containing sub-folders) where I have static HTML files e.g. http://domain.tld/physical-folder/sub-folder/index.html
      Even these appear to be stripped of their html. Please can you suggest me, on how I can disable the rule for the physical-folder and its sub-folders. Hope I have been able to explain myself.
        • 4626
        • 57 Posts
        A quick and easy (though limited) way would be to put a .htaccess file in that folder as well with:
        RewriteEngine Off
        


        Another idea (better maybe for the future) is to try to put:
        RewriteCond %{REQUEST_FILENAME} !-f
        

        before the first line in my previous code.
        So it looks like:
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} ^.*\.html$
        RewriteRule ^(.*)\.html$ $1 [R,L]
        
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
        


        I haven’t tested it though but I think it should work...
          • 24278
          • 165 Posts
          Wonderful -- it works.

          I haven’t tested in extensively, but on first cut, it works as expected.

          Carl, thanks, once again.

          One last thing, i dont know if it is possible (hope it is grin)...

          Currently my urls (alias and path enabled) look like
          http://www.domain.tld/folder/document?page=2
          where the page= is used for breaking up the *content* into multiple pages.

          Can I have my urls (for SEO reasons) to look like this
          http://www.domain.tld/folder/document-2 or .../document/2
            • 4626
            • 57 Posts
            Hi again...

            You could try this (only handles 1-9 pages (should be enough shouldn’t it)

            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_URI} ^.*\.html$
            RewriteRule ^(.*)\.html$ $1 [R,L]
            
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)-([1-9])$ index.php?q=$1&page=$2 [L,QSA]
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
            

            http://www.domain.tld/folder/document-2 => http://www.domain.tld/index.php?q=folder/document&page=2
              • 24278
              • 165 Posts
              Hi, sorry for the delay in replying.

              Adding the following to .htaccess as indicated...
              RewriteRule ^(.*)-([1-9])$ index.php?q=$1&page=$2 [L,QSA]
              


              There seems to be the same problem as earlier, where all images and styles seem to vanish.

              The apache log follows
              127.0.0.1 - - [22/Mar/2007:23:19:43 +0530] "GET /go/people/profiles/test-profile HTTP/1.1" 200 2768
              127.0.0.1 - - [22/Mar/2007:23:19:43 +0530] "GET /favicon.ico HTTP/1.1" 404 1276
              127.0.0.1 - - [22/Mar/2007:23:19:43 +0530] "GET /assets/templates/default/print.css HTTP/1.1" 404 1276
              127.0.0.1 - - [22/Mar/2007:23:19:43 +0530] "GET /assets/templates/default/sitestyle.css HTTP/1.1" 404 1276
              127.0.0.1 - - [22/Mar/2007:23:19:43 +0530] "GET /assets/js/pop.js HTTP/1.1" 404 1276
              127.0.0.1 - - [22/Mar/2007:23:19:43 +0530] "GET /assets/images/bookmark/delicious.png HTTP/1.1" 404 1276
              


              I appreciate your time and effort.
                • 4626
                • 57 Posts
                Hi again,

                I don’t really understand why mod_rewrite doesn’t want to do it the way I want to (I guess I don’t know enough!).

                A quick solution is:
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(.*)\.html$ $1 [R,L]
                
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(.*)-([0-9]+)$ index.php?q=$1&page=$2 [L,QSA]
                
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
                  • 25663 MODX Staff
                  • 12,272 Posts
                  Its sounds like it’s acting like MODx is installed in a subfolder, and you don’t have a base href in your template and the appropriate adjustments to the rewrite base in your htaccess.
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 24278
                    • 165 Posts
                    @carl -- the last solution does not seem to work. No chnage in URL, still appears as ....document?page=x -- but no issues with either css or images.

                    @ryan -- modx is not setup in a sub-folder and the base href appears to be correct in the template. The other suggestions by carl did work.

                    Man these .htaccess directives are confusing grin
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      This is the best explanation I have found to date.

                      http://corz.org/serv/tricks/htaccess2.php

                      Not to mention the really amazing stuff he’s got on the rest of his site!
                        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