We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11144
    • 10 Posts
    Currently fighting with htaccess to rewrite http://domain/product/category?tags=x to a more friendly http://domain/product/category/x

    I have tried a number of different versions and nothing has worked but a page error. Below is the latest and greatest attempt.

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteBase /
    
    RewriteRule ^category/(.*)$ category?tags=$1 [L,NC]
    
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


    Any help or suggestions would be greatly appreciated. Thank you.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      I think you’ll need to put the rules in a different order... and adjust them a bit... try this:

      RewriteBase /
      
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
      
      RewriteRule ^product/category/(.*)$ product/category?tags=$1 [L,QSA]
      
      


      And I suspect you’ll need that "QSA" for "query string append"... really the authority here is the apache docs.

      it’s a bit tricky to have this happen in one .htaccess file... if I were you I might try creating a dummy "category" directory with a dummy "category" file in there, and putting a separate .htaccess file in there, just to make sure that the rules from the main .htaccess file didn’t interfere...
        • 22303 MODX Staff
        • 10,725 Posts
        The better approach IMO is to use the OnPageNotFound event and attach a Plugin that checks the REQUEST_URI (I usually just explode them into segments) against whatever custom friendly URL patterns I am creating, set the appropriate REQUEST vars for the real page, and use $modx->sendForward(). See this post for an example.