We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49407
    • 159 Posts
    Since I'm using friendly URLs, I want to allow people to type in mysite.com/resource-alias/10 but I don't want to have to create a nested resource aliased "10", that would just pile up umpteen resources since this is front-end user generated content.

    Instead I would like to have MODX ignore numbers in the URIs, taking the person to the "resource-alias". I could then parse the URI with a snippet to get the resource's item number and return the content from my custom table.

    Currently I have to do this URI parsing on an error page and am unable to make a resource for "user-post", "user-page", "image", "video", etc. because MODX just tries to take the person to the number at the end of the URI, and that resource doesn't exist. With the many, many growing comment-able user content types it's getting rather messy to manage the so-called error page snippet efficiently.

    This question has been answered by Jako. See the first response.

      • 28432
      • 372 Posts
      You can use sendForward in a plugin on OnPageNotFound system event.
      https://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.sendforward

      Like :
      If -> resource-alias -> then sendForward -> else (nothing to do it will redirect to error page).
      $modx->sendForward(14);

      Here resource-alias is ID 14
        • 49407
        • 159 Posts
        Hi Steeve! That could work with a switch quite efficiently. I did just stumble on the Custom URLs extra, but can't make any sense of how to make it catch /resource-alias/ in the URI and hold to it.

        I'll try your suggestion and see if it's as easy as it looks. Sure would make coding the models for each user generated content type MUCH more organized and less obfuscated.

        Right now I have post views, likes, comments, etc. all being processed by this single "error" page. It's a nightmare. LOL

        Thank you for your insight!
        • discuss.answer
          Please try the CustomRequest extra for this.
            • 49407
            • 159 Posts
            I tested Steeve's suggestion. That worked well.

            Then I tried Jako's extra. I prefer the CustomRequest extra since it does the same thing with a nice interface.

            Thank you for the help guys!