Sitecore 根据 Sitecore 树中定义的项目名称生成 URL,
http://samplewebsite/Pages/Sample Page
但是我们的客户有兴趣降低所有 URL(页面/示例页面)的大小写,并使用连字符(示例页面)格式化空格。
我怎样才能做到这一点?
Sitecore 根据 Sitecore 树中定义的项目名称生成 URL,
http://samplewebsite/Pages/Sample Page
但是我们的客户有兴趣降低所有 URL(页面/示例页面)的大小写,并使用连字符(示例页面)格式化空格。
我怎样才能做到这一点?
在您的 web.config 中,您可以添加 节点<replace find=" " mode="on" replacewith="-">
以<encodeNameReplacements>
使用连字符格式化空格。不过要小心 - 这意味着您不能再在项目名称中使用连字符(因为 Sitecore 会尝试查找其中包含空格的项目)
要小写您的 URL,您可以使用规则引擎,如 John West 在此处描述的:
使用 Sitecore 规则引擎控制项目名称
如果您在 App_Config/Include 中使用自定义配置文件,则可以在您的<sitecore>
和</sitecore>
标签之间使用以下配置补丁。这会将您的 URL 中的空格更改为破折号,并且不允许内容编辑器在其项目名称中使用破折号。
<encodeNameReplacements>
<!-- Replace spaces in URLs with dashes -->
<replace mode="on" find=" " replaceWith="-" />
</encodeNameReplacements>
<settings>
<setting name="InvalidItemNameChars">
<!-- Disallow dashes in item names for content editors because the above rule causes the page to crash -->
<patch:attribute name="value">-\/:?"<>|[]</patch:attribute>
</setting>
</settings>
连字符替换的空格可以<encodeNameReplacements>
用Sitecore.config
.
要对所有 url 使用小写字符,您需要扩展LinkManager
类。它们都在这里解释:
http://csuwannarat.wordpress.com/2011/07/17/how-i-make-seo-friendly-sitecore-urls/
John West 在这里也发布了一个出色的解决方案:http ://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Use-the-Sitecore-Rules-Engine- to-Control-Item-Names.aspx