We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54969
    • 6 Posts
    Hi all, this issue hurts my brain.

    On many modern sites I see this pattern, but haven't figured out how to do it with modx yet.

    Say I have a user who clicks on a link on Facebook with the following url: mysite.com/event/3rf78gh9 they will, with my mod_rewrite rule hit a page more commonly known as

    index.php?id=23&eventId=3rf78gh9
    


    This works with the following Rewrite_rule.

    RewriteRule ^event/([^/]+)/?$ event/?eventId=$1 [L]
    


    My scenario is of cause a bit more complex then this, and I would really like to be able to also do the following:
    index.php?id=24&eventId=3rf78gh9
    

    Which should translate to
    mysite.com/event/3rf78gh9/messages
    

    Where id 24 is messages

    However i can't figure out how to create that type of mod_rewrite rule, please come up with suggestions for this.

    Now being a perfectionist I would also like to have my links generated with the same rules. Eg.
    [[~24 &eventId=`3rf78gh9`]]
    


    Is it even possible with modx
    Best
    Moonkin


      • 54969
      • 6 Posts
      Update

      I solved the mod_rewrite rules, so that is no longer an issue.
      If anyone is looking to do something similar here's the rules:
      RewriteRule ^event/([A-Za-z0-9-]+)/?$ event/?eventId=$1 [N]
      RewriteRule ^event/([A-Za-z0-9-]+)/messages.html$ event/messages.html?eventId=$1 [L,QSA]
      


      Second part is still up in the air.

      How would one have
      [[~24 &eventId=`3rf78gh9`]]
      
      //Be parsed to 
      event/3rf78gh9/messages.html
      


      I think I could create a small snippet for writing the urls, but is there another way?

      Best
      Moonkin
        • 3749
        • 24,544 Posts
        In theory, you could do it with .htaccess, but it would be simpler to do something like this (untested):

        [[CreateUrl? &docId=`24` &eventId=`3rf78gh9`]]



        /* CreateUrl snippet */
        return MODX_BASE_URL . 'event/' . &eventId . '/messages.html';
        



        You didn't have '24' in your example URL, so I didn't know what to do with it in the code.


          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
          • 54969
          • 6 Posts
          Hi Bob

          I think that is the way I'll be going, Thanks for taking the time to look at the this.

          Best
          Moonkin