We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26104
    • 36 Posts
    I have a little bit of code which may be added to modX in the next release. When using Friendly URLS without URL paths, the full URI will be passed to the q=, if someone adds another slash and some content this content will also be interpreted. Like this: http://www.mysite.com/somepage will go to somepage, when this is changed into: http://www.mysite.com/somepage/somebogus/somemorebogus. The page won’t be displayed and you will be pointed to the root doc. I had to solve this, because I’m building a plugin to be able to use the friendly urls to pass on more than one argument. The plugin is described here.

    The change I made are in the file "manager/includes/document.parser.class.inc.php"

    I changed this piece of code (starting on line 332):
    if ($this->config['use_alias_path'] == 1) {
                $this->virtualDir= dirname($q);
                $this->virtualDir= ($this->virtualDir == '.' ? '' : $this->virtualDir);
                $q= basename($q);
            } else {
                $this->virtualDir= '';
            }
    


    into:

            if ($this->config['use_alias_path'] == 1) {
                $this->virtualDir= dirname($q);
                $this->virtualDir= ($this->virtualDir == '.' ? '' : $this->virtualDir);
                $q= basename($q);
            } else {
                $this->virtualDir= ''; 
                // Strip everything after the first slash from the alias. Added by Sander van der Heyden - Deactro BV
                $arr = explode('/',$q); 
                $q = $arr[0]; 
            }
    


    Now it is possible to add whatever bogus you want behind the alias without changing the page that is displayed. I hope you guys think this little bit of code is usefull to add in next versions of ModX, so I don’t have to change it in future development projects of mine smiley

    A possible next step could be changing the MakeUrl function to make sure it can also create fully friendly urls.