Hey, has anyone ever been able to get friendly alias paths to work on only one container or document? For instance, I want to have a section of the site, such as:
www.mysite.com/mysection/articlename
www.mysite.com/mysection/article2name
But the rest of the site should appear to be top level, such as:
www.mysite.com/regularpage
www.mysite.com/regular2page
Is that possible?
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
-
☆ A M B ☆
- 24,524 Posts
No, it won’t work. Setting friendly alias paths will cause the URLs for all pages to reflect the Resource Tree structure.
Aha. Thanks for the quick reply.
What about prepending every alias name in that container with ’mysection/’ and then placing the page name afterwards - would that work? And if that would work, would a chunk work there as well?
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
-
☆ A M B ☆
- 24,524 Posts
Dunno; you can always give it a try. I seem to remember something about / being disallowed in the alias, though.
-
MODX Staff
- 10,725 Posts
FWIW in MODX 2.1 (currently in the final Release Candidate stages), you can override and specify the full URI for any Resource regardless of the Alias Path settings.
Thanks for the tip on 2.1, but I think I’m sticking with Evo for this one. Haven’t made the jump to Revo yet, no sites need the size requirements and I like my familiarity. I just tried putting in the forward slash and MODX strips it every time. I’m assuming there is similarly no way (in Evo) of putting documents in a subdomain, but within the same site/install? Thanks!
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
-
☆ A M B ☆
- 24,524 Posts
This behavior can be modified in a plugin using the OnStripAlias event.
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;
}
}
Susan, thanks for the code, that should handle it fine. Will that code replace everything except the forward slash, or do I need to edit the RegEx in the function?
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
-
☆ A M B ☆
- 24,524 Posts
No, no! That code is the code in the parser that strips the alias. The plugin will override the code in this function.
I would copy the function’s code, only modifying the part that strips non-alphanumeric characters.
$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;
Note the difference in the first preg_replace regular expression. The escaped / (\/) at the end adds the / to the original alphanumeric characters and _ and - that are allowed. I think this will do what you want; regular expressions are not my favorite subject.
Lol I can imagine. I started reading about regex once and numbed my brain. I’ll give it a shot when I’m up to it and see if it works; if it does, I’ll let you know. Thanks again!
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein