We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24414
    • 45 Posts
    I have Friendly URLs turned on, and wanted to have processed URLs that point at my home page to be pointed at the root of my site, but I could not find a way of creating an alias of ’ ’ (which is logical really). The rest of my URLs are just set to have a ’/’ appended to them and no prefix.

    With the home page I wanted links to point to:

    *ttp.x2.dev/

    instead of:

    *ttp.x2.dev/1/

    I ended up creating a plugin that listens to ’OnWebPagePrerender’, and simply rips off the end of the link.
    Is there a better way to do this?

    $output = $modx->documentOutput;
    $pattern = '/href=\"1\/\"/';
    $replacement = 'href="/"';
    $modx->documentOutput = preg_replace($pattern, $replacement, $output);
    
      • 22303 MODX Staff
      • 10,725 Posts
      You can always create a link to the site root with the simple tag [*site_url*] (or [*base_url*] if you don’t want the hostname and protocol included in the URL). Not sure why you would want to append a / to every pages alias, but your plugin seems like a decent solution to your scenario.
        • 24414
        • 45 Posts
        The only reason I want the URLs to be formatted like this is because I wanted to replicate my usual site structure, I was also concerned by the idea of duplicate content in search engines.

        The only place where this has proved to be an issue so far was in using DropMenu, but I suppose looking at the problem it would be apparent in the use of any automated means of creating URLs that will include a home link.