We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36702
    • 76 Posts
    I’m using friendly URLs, and this rewriting works as expected:
    # The Friendly URLs part<br />RewriteCond %{REQUEST_FILENAME} !-f<br />RewriteCond %{REQUEST_FILENAME} !-d<br />RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

    For example http://domain.com/about is rewritten as http://domain.com/index.php?q=about

    But for a specific page (with alias "book") I want to have a snippet that looks up book details from another database.
    That is, I want to rewrite http://domain.com/book/2153 to http://domain.com/index.php?q=book&bookid=2153
    To do this I’ve added another rewrite rule:
    # The Friendly URLs part<br />RewriteCond %{REQUEST_FILENAME} !-f<br />RewriteCond %{REQUEST_FILENAME} !-d<br />RewriteRule ^book/([0-9]*)$ index.php?q=book&bookid=$1 [L,QSA]<br />RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

    This seems to work correctly for all pages, and the snippet in "books" gets the bookid no problem.
    BUT - no css stylesheet is being used for any page!

    And if I type the css URL directly into the browser address bar
    http://domain.com/assets/templates/default/site.css
    it just shows the home page - not the stylesheet

    If I remove the new rewrite rule, the css works fine.

    Can anyone please suggest what might be going on?
      • 27147
      • 53 Posts
      I might be wrong but I don’t think you can stack RewriteRules under one block of RewriteConds.

      Try:

      # Book snippet
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^book/([0-9]*)$ index.php?q=book&bookid=$1 [L,QSA]

      # The Friendly URLs part
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
        • 36702
        • 76 Posts
        Ha - many thanks shuriken - that did the trick!

        (although I still don’t understand why the original version seemed to work for pages but not css)
          • 27147
          • 53 Posts
          You’re welcome smiley

          The reason is that the RewriteConds were not being applied but the FURL rule was (when the book rule didn’t match). The conds check to see if the resource exists on the filesystem before handing over to MODx. If your css sheets were MODx documents they would have worked also.