Sitecore - rewrite “_” to “-” in urls but going to 404

柔情痞子 提交于 2019-12-12 10:38:32

问题


I am using Sitecore 7.5 and replacing two things

<replace mode="on" find=" " replaceWith="-" />(Space with hyphen) 
<replace mode="on" find="_" replaceWith="-" />(underscore with hyphen) 

Replacing space(" ") with hyphne(-) is working fine but in the case of underscore(_) its changing in hyphens(-) but redirecting to 404, any idea?

We can manage this by Event handler but don't want to do that way.


回答1:


I commented on another answer that the problem is that when resolving the items, the incoming has the reverse replacements applied. Since you have 2 replacements both mapping to "-" then on incoming it fails since it tries to replace "-" with space initially, but some of those hyphens should be underscore but it has no idea which one should be which.

For example, given path: /path to some/item_url then the generated url is /path-to-some/item-url.

On incoming, the reverse replacements are replied, and Sitecore is now looking for /path to some/item url, which does not exists and so a 404 is thrown. Since the "_" (underscore) was replaced by a "-" (hyphen), on incoming the "-" (hyphen) is replaced with " " (space). Since there are no hyphens left to replace, it cannot replace with underscore.

Take a look in Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel and you will see a call to MainUtil.DecodeName(args.Url.ItemPath) where the EncodeNameReplacements are applied.

You are better using an event handler to deal with these in the first place so you don't then need worry about any kind of mapping.



来源:https://stackoverflow.com/questions/31004813/sitecore-rewrite-to-in-urls-but-going-to-404

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