我有一个情况,我的客户希望有SEO友好的URL,为他们的文档和这些URL下流到客户端文档。下面是一个示例设置:
根部
- Group1 (custom url=/groups/ma/salem/group1)
- Page1
- Page2
- Group2 (custom url=/groups/ma/boston/group2)
- Page2
- Page4
- etc.
url希望Page1、Page2、Page3、Page4继承其父级的自定义url,并且是:
当我设置自定义URL路径时,它只影响该文档,子文档保持不变:
可以在Kentico中实现这一点,而不需要修改树结构以包含URL部分?
有没有一种方法可以覆盖ResolveURL()函数,这样我就可以返回SEO友好的URL了吗?
我用的是Kentico 8.1
发布于 2014-10-10 13:21:25
在树中创建这些文档肯定是最简单和最安全的解决方案,但是为了避免这种情况,我看到了另外两个选项。
1)创建URL重写规则来模拟这种树的层次结构
2)捕获事件前插入的文档,并根据需要设置自定义URL路径。
代码可能如下所示:
DocumentEvents.Insert.Before += DocumentInsert_Before;
private static void DocumentInsert_Before(object sender, DocumentEventArgs e)
{
TreeNode node = e.Node;
if (node.NodeAliasPath.StartsWith("/groups/group1")) {
string safeNodeName = TreePathUtils.GetSafeDocumentName(node.DocumentName, CMSContext.CurrentSiteName);
string customPath = "/groups/ma/salem/group1/" + safeNodeName;
// Handle multiple dashes
customPath = TreePathUtils.GetSafeUrlPath(path, CMSContext.CurrentSiteName, true);
node.DocumentUrlPath = customPath;
}
}
https://stackoverflow.com/questions/26264157
复制相似问题