Blog Sections Open
Allowing Duplicate Aliases Only Across Different Parents
Duplicate aliases are useful when two different branches share the same product naming, but they still need to stay unique within the same parent.
The built-in “allow duplicate aliases” option is useful for catalogs, but the naive version can still let two identical aliases appear under the same parent. That creates a real collision, not just a convenient reuse of a slug in different branches.
Desired behavior
These URLs should be valid at the same time:
tv/samsung/product.html
photo/samsung/product.html
But two children inside the same parent should not resolve to the exact same alias.
Patch idea
A reliable approach is to checking alias uniqueness against the current parent both for generated aliases and for manually entered aliases. That keeps branch-level reuse while preventing true collisions.
Automatic alias check
else {
if ($modx->db->getValue("SELECT COUNT(id) FROM " . $tbl_site_content .
" WHERE id<>'$id' AND parent=$parent AND alias='$alias'") != 0) {
$cnt = 1;
$tempAlias = $alias;
while ($modx->db->getValue("SELECT COUNT(id) FROM " . $tbl_site_content .
" WHERE id<>'$id' AND parent=$parent AND alias='$tempAlias'") != 0) {
$tempAlias = $alias . $cnt;
$cnt++;
}
$alias = $tempAlias;
}
}
Manual alias check
$docid = $modx->db->getValue("SELECT id FROM " . $tbl_site_content .
" WHERE id<>'$id' AND alias='$alias' AND parent=$parent LIMIT 1");
If the alias already exists under the same parent, stop the save and show the duplicate-alias warning. If it exists only elsewhere in the tree, allow it.
Why this matters
This pattern is especially useful for product catalogs, multilingual branches, and media trees where repeated naming is natural but exact sibling duplicates are not acceptable.
Serving AJAX Variants with Separate Cache Logic
If one URL needs both a full-page response and an AJAX-only response, treat them as different cache contexts instead of hoping one cache file can safely serve both.
Allowing Duplicate Aliases Only Across Different Parents
Patch alias handling so documents can share an alias in different branches without creating identical URLs under the same parent.