所以我的内容结构为Root -> Folder -> Content page
。这个的自然网址是/foldername/pagename
,我正试图弄清楚如何使它始终只是/pagename
。
我可以将/pagename
重定向到/foldername/pagename
,但它仍然在地址栏中显示为后者。我在web.config中使用URL重写了,我有这个:
<rule name="Content" stopProcessing="true">
<match url="^Content/(.*)" />
<action type="Rewrite" url="/{R:1}" />
</rule>
但它似乎没有做任何事情。任何想法如何设置我的Kentico网站来处理URL,好像/foldername
根本不存在?
答案 0 :(得分:3)
实现这一目标的两种方法。
在页面上手动设置URL路径。在Pages应用程序中,打开页面,然后单击URL选项卡。填充&#34;路径或模式&#34;具有路径的字段,例如/pagename
如果您对手动设置网址路径不满意,请创建global event handler以在文档创建时设置正确的URL路径(也许还可以更新文档)。这是一个例子:
[assembly: RegisterModule(typeof(PagePathModule))]
public class PagePathModule : Module
{
public PagePathModule() : base("PagePathModule") { }
protected override void OnInit()
{
DocumentEvents.Insert.After += DocumentInsertAfter;
}
private static void DocumentInsertAfter(object sender, DocumentEventArgs e)
{
var node = e.Node; // TreeNode of the created document
var urlPath = "/" + node.DocumentName; // Use the document name as the path
node.DocumentUseNamePathForUrlPath = false; // Ensure that a custom URL path is used
node.DocumentUrlPath = TreePathUtils.GetSafeUrlPath(urlPath, node.NodeSiteName); // Set the document URL path
node.Update();
}
}
您应该确保从路径中删除不必要的字符。