We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31140
    • 8 Posts
    Hi guys,
    I am looking for a way to be able to have a customized URL in modx, but generated by scripts, not written manually in alias field of resources
    more specifically, I want to build a friendly URL with my own designed format, and better in names without IDs, like this

    www.domain.com/store-name.html and www.domain.com/category/product-name.html, because all these pages are build up with snippet, how would I achieve this customized URL in modx? Is there any way I can overwrite alias of URL dynamically, or using variables to build URL alias like what TV does?
    Just give me some directions, it would help.

    Thanks
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      You could write a plugin that fires when the document is saved and set the alias value via the code in the plugin.
        • 22303 MODX Staff
        • 10,725 Posts
        Actually, if you are using one Resource to dynamically render multiple pages and want friendly URLs for each distinct view, use a plugin OnPageNotFound to detect when a REQUEST_URI matches your defined pattern and the sendForward() method to render the actual Resource from the requested URL. Then you just need a way to generate your custom URLs in your Snippet. See this post for a simple example.
          • 31140
          • 8 Posts
          Quote from: OpenGeek at Aug 30, 2010, 03:53 PM

          Actually, if you are using one Resource to dynamically render multiple pages and want friendly URLs for each distinct view, use a plugin OnPageNotFound to detect when a REQUEST_URI matches your defined pattern and the sendForward() method to render the actual Resource from the requested URL. Then you just need a way to generate your custom URLs in your Snippet. See this post for a simple example.
          Thank you for you reply! this is what I need. Yes, I do use one resource to render multiple pages and want to customize the URL different, I will try to write a plugin using sendForward().
            • 36702
            • 76 Posts
            I have a site where custom URLs are handled by mod_rewrite in .htaccess. Various RewriteRules extract the different parts and send them to the correct document, where a snippet then works out what to display.

            Is there any advantage/disadvantage to doing it this way vs the plugin/sendForward method described in the linked post?

              • 31140
              • 8 Posts
              Quote from: twz at Aug 30, 2010, 08:39 PM

              I have a site where custom URLs are handled by mod_rewrite in .htaccess. Various RewriteRules extract the different parts and send them to the correct document, where a snippet then works out what to display.

              Is there any advantage/disadvantage to doing it this way vs the plugin/sendForward method described in the linked post?


              I thought about this solution too, I used to want to configure apache to rewrite URLs to index.php with different parameters, but I actually want to have a center place to build URL, both for expose and click. I looked for solution in modx itself, so that I can assemble URL with a central place.
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: twz at Aug 30, 2010, 08:39 PM

                Is there any advantage/disadvantage to doing it this way vs the plugin/sendForward method described in the linked post?
                I think it really just depends on what is easier for you to maintain, PHP code or rewrite rules.
                  • 17499 ☆ A M B ☆
                  • 872 Posts
                  Quote from: OpenGeek at Aug 31, 2010, 10:57 AM

                  I think it really just depends on what is easier for you to maintain, PHP code or rewrite rules.

                  Does it not go faster with the Rewrite rule ?