Sitecore - rewrite “ ” to “-” in urls but still allow dashes as legal item names

元气小坏坏 提交于 2019-12-05 10:31:17

So, if I am assuming correctly, you want to replace spaces in item names with some other SEO-friendlier character. Whatever replacement you configure, you would need to apply the transformation on both sides of the equation (pun intended). So '--' or '_' will have to become illegal item name characters.

I generally think it's a bad idea to do this and would rather have my content editors determine the exact urls to their content.

But if you absolutely need to implement this as a rule, one of the solutions out there is to implement a custom handler to change your real item name while leaving the item display name in its original form.

Hope this helps.

Which version and build of Sitecore are you using?

I've just taken a look through Sitecore.Links.LinkProvider in Sitecore.Kernel and the BuildItemUrl method only replaces characters encodeNameReplacements on the path part of the URL so it should leave your hostname alone.

I would expect the same to happen to reverse, and looking at Sitecore.Pipelines.HttpRequest.SiteResolver the SiteContext is resolved by matching the requested Uri to the defined sites. Further down the process Sitecore.Pipelines.HttpRequest.ItemResolver decodes the Item Url but the Site has already been resolved at this stage.

I presume you have set the hostName attribute on the <site> elements? Having you tried setting the targetHostName attribute as well? Have you tried setting multiple hostNames, I don't expect it to work with spaces but worth a try if what you are saying is true:

<site name="website" hostName="my-site.com|my site.com"  ... />

I tried replicating your issue on my local machine but it worked as expected for me... Unless you are working with very strange character sets then this is still the best way of encoding names in my opinion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!