2014-10-08 47 views
0

我有一種情況,我的客戶想要爲他們的文檔提供SEO友好的URL,並且這些URL可以流向客戶端文檔。下面是一個例子設置:孩子文檔可以繼承Kentico中的父母的自定義URL路徑

    • 組別1(自定義URL = /組/ MA /塞倫/組1)

      • 第1頁
      • 第2頁
    • 組2(自定義URL = /組/ MA /波士頓/組2)

      • 第二頁
      • 第四頁

的想第1頁,Page2,Page3,Page4繼承它的父母的自定義網址,並且是:

  • /組/ MA /塞倫/組1 /第1頁
  • /組/ MA /塞倫/組1 /第2頁
  • /組/ MA /波士頓/組2 /第2頁
  • /組/ MA /波士頓/組2/3頁

當我設置自定義URL路徑,只會影響該文檔和子文檔保持不變:

  • /組/ 1組/第1頁
  • /組/組1/2頁
  • /組/組2/2頁
  • /組/組2/3頁

可這在Kentico,而無需修改樹狀結構包含的URL部分可以實現嗎?

有沒有辦法來重寫ResolveURL()函數,所以我可以返回SEO友好的URL?

我使用Kentico 8.1

回答

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; 
    } 
} 
相關問題