We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44793
    • 19 Posts
    I created a new plugin so we could add some top-level friendly aliases in a sub-folder of the root while friendly alias paths is enabled. So, for example, domain.com/alias1 could redirect to domain.com/path/to/deep/link and domain.com/alias2 could redirect to anothersite.com/path/to/page.

    The reason for the plugin is so we can have an easy way to manage top-level aliases without cluttering the root folder of MODx with weblinks. It may not be the most efficient or elegant but it seems to work and is easy to manage. If you have suggestions, let me know.

    Setup:

    • Add the code below as a new plugin in MODx named "Top-level friendly aliases"
    • Set the value of $aliasesFolder to the alias for the folder where the weblinks/aliases will be located
    • Set it to listen to the OnPageNotFound system event

    Note: requires "use friendly URLs", "use friendly aliases" and "use friendly alias path" to be enabled.

    Once it’s setup, to add a top-level alias, add a new weblink to the links folder you defined for $aliasesFolder, set the alias and weblink properties, save and publish and voila.

    // by Mike Henry 2009
    // BEGIN TOP-LEVEL FRIENDLY ALIASES
    
    $aliasesFolder = 'links';
    
    function strip_trailing_slash($string) {
    	if (substr($string, strlen($string) - 1) == '/')
    		return substr($string, 0, strlen($string) - 1);
    	return $string;
    }
    
    $requestedPath = strip_trailing_slash(strtolower($_SERVER['REQUEST_URI']));
    
    $docId = $modx->documentListing[$aliasesFolder . $requestedPath];
    if (is_numeric($docId)) {
    	$modx->sendForward($docId);
    	exit;
    }
    
    // END TOP-LEVEL FRIENDLY ALIASES
    
      • 20413
      • 2,877 Posts
      Nice! cool
        @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