In Sitecore, there is an easy of avoiding the %20 signs in your URL’s. To clarify: If you have an item with a space in the name, the space will appear in the URL as a %20 sign. For example, the item with name “read this” will appear as:
To avoid this, Sitecore have implemented a simple encodeNameReplacements function. In the sitecore.config, Sitecore have defined a list of character replacements:
<encodeNameReplacements> <replace mode="on" find="&" replaceWith=",-a-," /> <replace mode="on" find="?" replaceWith=",-q-," /> <replace mode="on" find="/" replaceWith=",-s-," /> <replace mode="on" find="*" replaceWith=",-w-," /> <replace mode="on" find="." replaceWith=",-d-," /> <replace mode="on" find=":" replaceWith=",-c-," /> </encodeNameReplacements>
To make a new replacement, simply add it to the list. In my example, I would like to replace space (” “) with a dash (“-“):
<replace mode="on" find=" " replaceWith="-" />
From now on, all my spaces will be replaced with a dash, and my “read this” page will now have this URL:
BEWARE OF THE INFAMOUS MEDIA LIBRARY REPLACEMENT BUG
In certain versions of Sitecore 7.x and Sitecore 8.1, Sitecore have made a mistake where any item in the media library with a – in the item name will be reversely replaced internally to a space, thus making the URL invalid.
In other words: If your space/dash replacement suddenly breaks media library URL’s, try removing any dashes from the media library item name and see if the problem goes away.
Sitecore support have several bug fixes for this, depending of the Sitecore version.
MORE TO READ:
- EncodeNameReplacements wildcard replacement happening before space-to-hyphen replacement? from Sitecore Community
- Having a problem with encodeNameReplacements not working from Sitecore Community
- Using replacement characters in Sitecore the right way by Reinoud Van Dalen