【问题标题】:Can the child documents inherit the Custom URL path of it's parent in Kentico子文档能否继承其父文档在 Kentico 中的自定义 URL 路径
【发布时间】:2014-10-08 18:43:32
【问题描述】:

我的客户希望为其文档设置 SEO 友好的 URL,并将这些 URL 向下传递到客户端文档。这是一个示例设置:

    • Group1(自定义 url=/groups/ma/salem/group1)

      • 第1页
      • 第2页
    • Group2(自定义 url=/groups/ma/boston/group2)

      • 第2页
      • 第4页

希望 Page1、Page2、Page3、Page4 继承其父级的自定义 url 并且是:

  • /groups/ma/salem/group1/page1
  • /groups/ma/salem/group1/page2
  • /groups/ma/boston/group2/page2
  • /groups/ma/boston/group2/page3

当我设置自定义 URL 路径时,它只影响该文档并且子文档保持不变:

  • /groups/group1/page1
  • /groups/group1/page2
  • /groups/group2/page2
  • /groups/group2/page3

在不修改树结构以包含 URL 部分的情况下,这是否可以在 Kentico 中实现?

有没有办法覆盖 ResolveURL() 函数,以便我可以返回 SEO 友好的 URL?

我正在使用 Kentico 8.1

【问题讨论】:

    标签: kentico


    【解决方案1】:

    在树中创建这些文档绝对是最简单和最安全的解决方案,但是如果您想避免这种情况,我看到了另外两个选项。

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      相关资源
      最近更新 更多