We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6726
    • 7,075 Posts
    Simple question really, and the custom alias plugin provides this feature but it has some other issues with stripping special characters out of URLs thus is not an option : How do I prepend the document’s ID to my URLs ?

    There is no built in TVs to add as prefix and of course [~[*id*]~] won’t work...

    Maybe a custom TV with an @EVAL ?

    CustomAlias is using the following code to retrieve the id and add it to the url :

    // Get the ID of the document, if you want to use it in your alias
    $id = '.'.$modx->event->params['id'];
    
    (.........)
    
     // Update the database
        $rows_affected = $modx->db->update(
          $fields,
          $table,
          "id = {$e->params['id']}"
        );
    
      .: COO - Commerce Guys - Community Driven Innovation :.


      MODx est l'outil id
      • 25663 MODX Staff
      • 12,272 Posts
      096 doesn’t have those issues with special characters and I suppose that you could take the same logic from the core now and update the custom alias plugin with that.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 6726
        • 7,075 Posts
        It means that there is no practical mean to prepend the url with the ID without using CustomAlias ?
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 25663 MODX Staff
          • 12,272 Posts
          I don’t think so automatically. You could of course always go back to the doc after saving and insert [*id*]- to prepend the alias, but that seems like extra work to me. I’d personally update the custom alias plugin, since it’s only introducing overhead when the document is saved and is otherwise out of the loop.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 6726
            • 7,075 Posts
            Ok thanks for the advice Ryan I’ll try to go ahead with that if it’s decided that we opt for this for the website I’d eventually need that feature...
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l'outil id
              • 25663 MODX Staff
              • 12,272 Posts
              Out of curiosity, why does the client want the Doc ID in every alias?
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 6726
                • 7,075 Posts
                That’s what he has posted here on the french boards (in french).

                He was afraid that if he changed title, the link to the resource would return a 404 page. I already explained to him before he posted that the alias was only updated if the alias field had no value, therefore changing the title would not change the alias. But that does not make sense to him to have an outdated alias : he wants it updated.

                His idea (because a friend of his has a website with that feature -> I don’t remember the url) is that the ID should be prepended to the url in such a way that the alias has actually no real value to locate the resource : only the ID is taken into account by the system. For instance in his example 214-il-fait-beau-en-mai.html would return the same document as 214-whatever-alias.html does.
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l'outil id
                  • 25663 MODX Staff
                  • 12,272 Posts
                  I suppose that’s a valid way to handle things. He will definitely need a custom plugin to address his requirement.
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 6726
                    • 7,075 Posts
                    Especially since this url scheme would mean handling 301 headers correctly since a document could have X aliases for one ID. And correct me if I am wrong but SEO Stricts URLs is not built to handle this kind of url patterns... that would mean building a plugin which would be a tweaked combo of CustomAlias and SEO Stricts URLs... tricky !

                    Plus, how much would that cost ?
                    I sure can’t be the one to write the plugin...
                      .: COO - Commerce Guys - Community Driven Innovation :.


                      MODx est l'outil id
                      • 2299
                      • 62 Posts
                      Hi, I’m the client laugh

                      The website I showed to davidm was this one : http://www.abcdrduson.com (french rap magazine). And indeed, the only important part in the URLs is the id number.

                      Example :
                      http://www.abcdrduson.com/interviews/interview-102-grain-de-caf--octobre-rouge-.html (current URL)
                      http://www.abcdrduson.com/interviews/interview-102-whole-new-title-.html (fictionnal updated URL)

                      But davidm pointed out a good point by asking how often do you need to change an page title. My opinion on this topic is probably biased by the fact that I’m currently creating the website I’m working on, and not simply keeping it up to date. I’m testing lots of stuff - content-wise - and therefore constantly changing page titles. But once the website will be launched, I agree that it should not be the case anymore, so, I guess my problem isn’t one, actually...

                      Anyway, thanks for helping, Ryan !