Sitecore - Rewrite "_" to "-" in URLs, but head to 404

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 (-) works fine, but in the case of underscore (_) its change in hyphens (-), but redirecting to 404, any idea?

We can control this Event handler, but we do not want to do this.

+7
sitecore
source share
1 answer

I commented on another answer that the problem is that when resolving elements in the application, reverse replacements are applied. Since you have 2 replacements, like mapping to "-" and to incoming, this happens with an error, because it first tries to replace "-" with space, but some of these hyphens should be underlined, but have no idea which one it should be.

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

With an incoming response, they will answer back, and Sitecore will now look for /path to some/item url that does not exist and therefore is called 404. Since the "_" character (underscore) has been replaced with a "-" (hyphen), when you enter "- "(hyphen) is replaced by" "(space). Since there are no hyphens that can be replaced, it cannot replace the underscore.

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

It is better to use an event handler to deal with them in the first place, so you do not need to worry about any comparison.

+10
source share

All Articles