We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38593
    • 129 Posts
    The title pretty much sums it up. Does MODX save the friendly url string for each resource in the database or does it build it from scratch each time it is needed by climbing the document tree?

    If it does save the url string in which table does that reside?

    If it does not save the string, why not? It seems that having the string pre-built so to speak would save processing time when MODX is building a webpage, especially when we are inserting links within content or menus.
      Pedalers Bicycle Tours my website forged with MODX
      vandergraaf-M static website generator for MODX
      • 42562
      • 1,145 Posts
      Let me guess here...

      1. Your .htaccess technically rewrites whatever, and that happens on the fly, check by deleting ya code in that .htaccess file.
      2. What is saved in your database is the freeze URI - check that column in the modx content resource table, and I think this too works n conjunction with the .htaccess code.
      3. I am not certain of any processing differencing, I mean the server has to do something, and a basic rewrite should not cost too much.

      ....but what do I know?
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • All that the rewrite does is rewrite any request it can't find the file or directory for to the index.php file with the actual URL (minus the domain.com part) as a query string. MODX is thus invoked (with the index.php script) and looks for the resource with that alias or alias path (however you have friendly URLs set to behave in the System Settings).

        The URL generated (with or without its path, and including the suffix specified for the document type, such as .html) can be saved using the Freeze URL option. This is saved in a field in the site_content table.

        A map of the entire Tree is generated and cached, so even without using the frozen URL it's not as expensive as it might be to generate these URLs. Also if the menu or other listing snippets are called cached then the URLs aren't generated on subsequent page requests anyway.

        Whether or not the frozen URL or these various caches are used is up to the developer of the snippet in use. And of course there are conditions under which a menu or other listing snippet cannot be cached, such as when pages are protected - if a cached menu is first generated and cached for an anonymous user, then even when a user logs in he'll get the same limited menu, likewise if it's first generated and cached for a logged-in user then all users will see the same whole menu.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 38593
          • 129 Posts
          Yes I understand that the server uses rewrite to connect the friendly url request with the appropriate modx resource id.

          But I am wondering about the friendly urls that are generated by modx itself for use within the html output it produces for a webpage whenever we use [[~123]] in our templates, chunks, etc. The URI column in the database only seems to save the portion of the friendly url appropriate to that resource (ie the page resource contains: coolpage.html, the sub-folder it sits in contains: subfolder/, etc) so modx still needs to climb the document tree each time it needs to generate the full url: .../folder/subfolder/coolpage.html. Which seems like extra processing time each time the page is served versus extra processing time only when the page is saved.
            Pedalers Bicycle Tours my website forged with MODX
            vandergraaf-M static website generator for MODX
            • 38593
            • 129 Posts
            @sottwell - Is there a config change that will save the entire url in the URI column? For some reason your reply didn't show before I typed previous reply. [ed. note: mrcycling last edited this post 8 years, 2 months ago.]
              Pedalers Bicycle Tours my website forged with MODX
              vandergraaf-M static website generator for MODX
            • You can configure makeURL to use different schemes, the default is "relative". The System Setting uses these same values https://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.makeurl
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 38593
                • 129 Posts
                Thanks for getting me looking in the right direction. MakeURL will serve for the purpose for the concept I am playing with.

                But please forgive my noobishness, what is the function of the $context variable in the MakeURL parameters?

                  Pedalers Bicycle Tours my website forged with MODX
                  vandergraaf-M static website generator for MODX
                • Specifies the context of the resource. MODX comes with two contexts, 'web' and 'mgr'. The default front-end context is 'web'. The 'mgr' context is for the Manager, and is primarily used to control user permissions.

                  https://rtfm.modx.com/revolution/2.x/administering-your-site/contexts
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 3749
                    • 24,544 Posts
                    $modx->makeUrl() doesn't actually create the URL. It calls the makeUrl() method of the context object that the resource belongs to ('web' being the default), so $modx->makeUrl() needs to know the context unless it's 'web'.
                      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
                      • 38593
                      • 129 Posts
                      Thanks to all for the help.

                      A little clarification on the goals behind my questions. I wrote a PHP script for my current website, that fetches the web pages from MODX and saves them as static files rather than serving them direct from MODX to each visitor. For this particular use I created a TV that held each page's static url, allowing me to manipulate the url for seo purposes without having to play musical folders in the resource tree.

                      I am now playing with another project and I want to use MODX's built in friendly urls. My initial approach was to simply append [[~[[*id]]]] to the top of the template, read that string when fetching the completed page and then strip it before saving the page as static html. But I figured there had to be a way to get the friendly url direct from MODX before fetching the content I intend to save and perhaps eventually make it a plug in rather than an external script as it currently is.
                        Pedalers Bicycle Tours my website forged with MODX
                        vandergraaf-M static website generator for MODX