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

    I don't know it title is correct, but I will try to explain what my goal is.
    Let say we have a resource called "Products" which is a container so it ends with "/".

    i.e.
    http://my_modx/Products/ -> returns content of resource 'Product'


    Now let say we have urls like this:

    http://my_modx/Products/some_product_name.html
    http://my_modx/Products/some_other_product_name.html
    ...
    http://my_modx/Products/some_product_name_as_well.html


    I wish that modx ignores that actually such resources doesn't exist and let me catch the urls and pass it to resource "Product" so I could process the name and return custom content as a result. (product are in custom table, they aren't resources).

    So idea is to make it work like it was a Product resource called with query like:
    ?product=some_product_name etc.

    The thing is to make it look like a friendly url!

    I appreciate you help.
      • 5340
      • 1,624 Posts
      I think this is a job for OnPageNotFound event

      Also have a look at Redirector

      Cheers
        • 38657
        • 3 Posts
        Thanks cipa (your nickname is rude in my language laugh)

        I find out that OnPageNotFound event might be a solution and so far with such a tiny code:

        if ($modx->event->name != 'OnPageNotFound') return;
        if(preg_match('/Products/',$_SERVER['REQUEST_URI'])) $modx->sendForward(2);
        return false;


        it seems to work!

        I also checked the Redirector but it is not what I need. I don't want any redirection at all.
          • 25586
          • 105 Posts
          I have been struggling with this for a while now. How does modx handle friend-urls? I which there was a cleaner way than to work with the OnPageNotFound.
            • 5340
            • 1,624 Posts
            What do you mean?
            How can MODX handle non-existing pages as friendly URLs except detecting that the page does not exist and redirecting to whatever page you want?
              • 25586
              • 105 Posts
              I was wondering how we can use the friendyURL function modx uses. I don't want to use the OnPageNotFound function, I rather use the build in functionality.
                • 33968
                • 863 Posts
                OnPageNotFound is very much... built in functionality smiley

                Think of it as 'OnResourceNotFound', ie. if MODx doesn't find a resource with an alias that matches the current URI, you can get it to do something else. And that's where you insert the code to look up your custom data view. It comes after looking for a MODx resource, but before returning a 404.

                The core devs actually recommend using this technique, have a look here for more info:
                https://forums.modx.com/thread/?thread=35476&page=1
                  • 25586
                  • 105 Posts
                  Ahhh great! Different than I thought how it would work but now I know this is the proper technique I will use it smiley

                  Thanks Lucas!
                    • 38657
                    • 3 Posts
                    True, "OnResourceNotFound" does the job very well. smiley