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

    I've got a couple of sites that want the same solution, so I'll keep it a little more global. There's a webshop setup and there's a API setup, just to name a few. But in general, they functionality is the same.

    I want a friendly URL with an additional parameter. So for example, webshop.com/product/10 should give the results of what would be webshop.com/product?product_id=10.
    In a similar way, an API needs api.com/users/13 to give the result of api.com/users?user_id=13

    But the /product/10 will always look for a child resource '10' under the 'product' parent.


    I get that probably should do something with the rewrite rules. But I'm not familiar with them. And from what I've looked up and found, nothing seems to work. So if anyone knows anything that could help me with this, that would be much appreciated. If it's possible at all.


    Just to be clear: the added parameters are to be used in custom database tables, that's why adding every child as a new resource isn't really an option.

    Thanks in advance for whoever has any suggestions.
      • 3749
      • 24,544 Posts
      I'm not sure I'm understanding you, but you can do this when creating a link (where 12 is the ID of the page you're linking to):

      [[~12? &product_id=`10` &user_id=`13`]]


      Those two params will go in the query string of the URL.

      Note that those are backticks, not single quotes in the tag.

      You could also populate the values from a productId on the page and the current user's ID (I'm not positive about the form of the second one):

      [[~12? &product_id=`[[*productId]]` &user_id=`[[modx.user.id]]`]]



        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
        • 48589
        • 33 Posts
        Thanks for the reply, but I’m afraid that’s not what I’m looking for. I’m not looking to create links with these parameters.

        What I want is to have a URL, i.e. domain.com/product/1, where 1 is the variable for the snippet to work with.
        In the normal MODX setup, the URL would be domain.com/product?id=1

        Basically, I want to clean up the URL part of the extra parameters.

        It now looks at ‘product’ (or in the desired URL at ‘product/1’) as the q parameter of the index.php file. I would want it to see the URL as q = product and otherParam = 1
          • 3749
          • 24,544 Posts
          Could you use a $_POST request? That would keep the params out of the URL altogether.

          If you need to use $_GET, you can look at the code of the Articles snippet, which does what you want. The Articles container is basically a routing page. It has a snippet that reads the URL and delivers the desired page.

            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