We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39535
    • 39 Posts
    Hi, I'm using MODX Revolution 2.2.6-pl (traditional).

    Normally I cannot create two resources with same parent with same alias as MODX won't let me save second resource.
    But if I create resource #1 and set its alias to, say, 'hello' and save it as unpublished, then I can create resource #2
    and save it published with alias set to 'hello' - MODX won't stop me.

    So for now I have two resources with the same uri. If I try to preview the published resource with 'hello' alias, the following happens:
    if id of unpublished resource is lower then that of published, it tries to display the unpublished page and so redirects me to homepage;
    if, on the contrary, id of published resource is lower than that of unpublished, it displays a published one.

    I tried to dig into MODX files and found out that if there are two resources with the same uri, say, 'hello', in $modx->aliasMap['hello'] will be the lowest id of documents with uri 'hello' regardless if the document is published or not.

    I'd call it a bug, because if MODX allows to have duplicate uris for unpublished resources, it should always show the published one when we request this uri (but not the one with lowest id as it does now). Or any alias duplication should be forbidden.

    What do you think about it?

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

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      To begin with, I think you should upgrade your site, if not to the 2.3.2 latest version then at least to 2.2.16 if you want to stay with the 2.2 branch.
        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
        Do you have the global_duplicate_uri_check System Setting on? It's off by default.

        It's rare, but a person could *want* duplicate pagetitles (which gives duplicate URIs). I was just looking at a site where there are dozens of duplicates. There are up to 20 resources with the same pagetitle -- all in the same context. They don't cause trouble because FURLs are off.

          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
          • 39535
          • 39 Posts
          Quote from: BobRay at Dec 22, 2014, 11:43 PM
          Do you have the global_duplicate_uri_check System Setting on? It's off by default.

          It's rare, but a person could *want* duplicate pagetitles (which gives duplicate URIs). I was just looking at a site where there are dozens of duplicates. There are up to 20 resources with the same pagetitle -- all in the same context. They don't cause trouble because FURLs are off.


          Thank you for your response,
          I have global_duplicate_uri_check System Setting off. But I don't understand why you asked because this setting when set checks duplicates in all contexts and when not set check duplicates in resource's context. My problem happens with resources in the same context.

          I have furls on. I don't understand your message about titles. I have duplicate aliases.
            • 39535
            • 39 Posts
            Quote from: sottwell at Dec 22, 2014, 07:51 PM
            To begin with, I think you should upgrade your site, if not to the 2.3.2 latest version then at least to 2.2.16 if you want to stay with the 2.2 branch.

            Thank you for your response,

            yes, you suggested me a good idea to upgrade MODX. But I was wondering if this a known bug or I'm just missing something.
              • 39535
              • 39 Posts
              Anyone else?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                With Friendly URLs enabled, the alias is usually automatically created from the pagetitle.

                Testing, it appears that you can create all the resources with the same alias you like - as long as they are unpublished. You can create one published resource with the same alias, then after that all subsequent attempts to save any resource, new or edited, with that same alias will cause an error.

                And, indeed, using the alias in a URL will cause a not-found condition if the unpublished aliases were created first (as they had to be in order to be created with a duplicate alias at all). [ed. note: sottwell last edited this post 11 years, 9 months ago.]
                  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
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I think this is a bug...at least I shall go and report it as such, unless you would like to report it yourself.
                    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
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Ah! Interesting. Clear the cache and you get this in the console
                    Resource URI page.html already exists for resource id = 9; skipping duplicate resource URI for resource id = 5
                    Resource URI page.html already exists for resource id = 9; skipping duplicate resource URI for resource id = 6
                    Resource URI page.html already exists for resource id = 9; skipping duplicate resource URI for resource id = 7
                    Resource URI page.html already exists for resource id = 9; skipping duplicate resource URI for resource id = 8
                    And subsequently a URL with the alias will load the published page, in this case #9.
                      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
                    • discuss.answer
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      So it looks like the bug is actually in the cache clearing upon saving the first published resource. It should have cleared the map and only listed the published one.
                        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