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

    A year ago I placed the topic on the Friendly Alias Paths.
    http://modxcms.com/forums/index.php?topic=37122

    We want to have slashes in the url aliasses but not according to the Document Path in the Document Tree.

    A Workaround was given by user ’bunk58’ to modify file manager/processors/save_content.processor.php.
    There the alias is modified by taking away illegal chars including the slash.
    The workaround worked fine on 0.9.* versions.
    But now we are already at Evolution version 1.0.3 and there the workaround is not possible anymore.
    The code is changed.

    I have tried to find the new location where to modify the MODX-code. MODX now uses a TransAlias plugin but changing that gives no solution.

    Does anybody have an idea what code to modify.

    In short: We want slashes in our URLs and not use the Friendly Alias Path in de config.

    Thanks in advance for all your help.

    Regards,

    Bert
      • 22303 MODX Staff
      • 10,725 Posts
      If not done already, can you please enter a feature request in JIRA for this? And attach any patches if you have any for any release?
        • 20413
        • 2,877 Posts
        Se manager/includes/document.parser.class.inc.php

        	/**
        	 * Format alias to be URL-safe. Strip invalid characters.
        	 *
        	 * @param string Alias to be formatted
        	 * @return string Safe alias
        	 */
            function stripAlias($alias) {
                // let add-ons overwrite the default behavior
                $results = $this->invokeEvent('OnStripAlias', array ('alias'=>$alias));
                if (!empty($results)) {
                    // if multiple plugins are registered, only the last one is used
                    return end($results);
                } else {
                    // default behavior: strip invalid characters and replace spaces with dashes.
                    $alias = strip_tags($alias); // strip HTML
                    $alias = preg_replace('/[^\.A-Za-z0-9 _-]/', '', $alias); // strip non-alphanumeric characters
                    $alias = preg_replace('/\s+/', '-', $alias); // convert white-space to dash
                    $alias = preg_replace('/-+/', '-', $alias);  // convert multiple dashes to one
                    $alias = trim($alias, '-'); // trim excess
                    return $alias;
                }
            }


        and apply the same changes.
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 3177
          • 137 Posts
          Hello Mrhaw,

          Yes, I found this routine also. I changed the line below
          $alias = preg_replace('/[^\.A-Za-z0-9 _-]/', '', $alias);
          

          to the following:
          $alias = preg_replace('/[^\.A-Za-z0-9 _-\/]/', '', $alias);
          


          This gives not the desired effect. The slash is still removed.
          After some searching I found the solution.
          Can the MODX-experts please check if I not mess anything up
          in another area of MODX?

          the solution lies in the fact that the function checks for a plugin in the OnStripAlias event. In MODX 1.0.3 there is such a plugin. It’s called "transalias". That plugin has a number of datafiles what to translate.
          Two files in there mention the slash to be translated to an empty string: utf8.php and utf8owercase.php.
          So, in those two files, the following lines should be removed: (They are at the top of the files)
           // File/path punctuation (usually not wanted, but might be wanted in some cases)
          '/'=>'',
          

          Since they are datafiles in the plugin, I don’t think this is a bug which should be changed. It is just a feature which should be clearly documented on the effect.

          So, "if you want to have slashes in the url and don’t want to switch on friendly alias path: Change the files in the transalias plugin."

          (Google, do your thing and pick this up!!)

          Regards,

          Bert


            • 20413
            • 2,877 Posts
            Good to know! Bookmarked smiley
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
              • 25663 MODX Staff
              • 12,272 Posts
              bertcatsburg that’s a solution for what you’re trying to accomplish. Feel free to submit a patch for an alternate transliteration routine with this in it so it will be part of future distributions (in JIRA please!).
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 22303 MODX Staff
                • 10,725 Posts
                FWIW, this should be an option (i.e. system setting) that affects the behavior of TransAlias. Similar options are already available in Revolution which should allow this to be done, though it may not be fully functional without some testing. I’ll do some testing later today and report on the current behavior in Revo.
                  • 3177
                  • 137 Posts
                  Yes, it would be nice to have this as a system setting.
                  I also requested/suggested this in the JIRA-bug: http://svn.modxcms.com/jira/browse/EXT-38

                  It gives the webmaster/webdeveloper the option to have slashes in the URL-Alias and thereby creating his own virtual document-tree regardless of the actual document tree. The actual document tree can still be displayed in the urls, he (the webmaster) only has to check the option "Friendly Alias Path" in the Config. But this "Friendly Alias Path" and the new config option "Virtual Document Tree" should be mutually exclusive I guess.

                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: bertcatsburg at Apr 28, 2010, 08:26 AM

                    It gives the webmaster/webdeveloper the option to have slashes in the URL-Alias and thereby creating his own virtual document-tree regardless of the actual document tree. The actual document tree can still be displayed in the urls, he (the webmaster) only has to check the option "Friendly Alias Path" in the Config. But this "Friendly Alias Path" and the new config option "Virtual Document Tree" should be mutually exclusive I guess.
                    I do not agree they should be mutually exclusive, or affect each other in any way. Any single node can simply represent multiple segments if you so choose, regardless if the parent paths are constructed into the scheme.
                      • 3177
                      • 137 Posts
                      Ok, but that makes it more complex.
                      Suppose I have checked "Friendly Alias Path" and also checked "Virtual Document Tree" (a.k.a. "I wanna have slashes in my URL Aliasses"), and suppose the document tree looks like the following:


                      [tt]- Root Doc
                      - Product Pages
                      - Shoes
                      - Product XYZ
                      [/tt]

                      And on page "Product XYZ" I have the URL Alias "sportsshoes/mens/the-best-for-playing-soccer",
                      then the final url will be:
                      "/product-pages/shoes/sportsshoes/mens/the-best-for-playing-soccer.html"

                      Might not be a problem, but should be clearly documented somewhere.