Read my previous blog post about SEO Friendly URLs? Go have a read, I cover several methods of achieving SEO Friendly URLs.

Did you read it? Did you read that part about encodeNameReplacements ? Yeah, I still don’t like them, but it seems like now we all have to deal with them at least.

Sitecore 8.1 seems to have slipped past the addition of the following config change:

<encodeNameReplacements> ... <replace mode="on" find=" " replaceWith="-"/> </encodeNameReplacements>

It was there in the release notes: https://dev.sitecore.net/Downloads/…/Sitecore%20Experience%20Platform%2081%20Initial%20Release/Release%20Notes

encodeNameReplacements section in Sitecore configuration file has been updated to replace “ ” (space) characters in item path with – (hyphen) by default when generating and parsing item URLs. (417279)

(Rather ironically, %20)

It’s also made it into Sitecore 8, Update-6… but not a single mention in the release notes…

Ooooh, SEO friendly URLs. OOTB. Except, it’s a trap!

In the blog post I wrote around the subject a few months ago, I tried to cover a lot of the problem areas and why the encode name replace are a bad idea and it’s better to deal with the problem at source. Prevention is better than cure! Most of us probably have some sort of URL prettifier in place already for existing projects, even the LaunchSitecore demo site includes a handler for this.

My initial concern was that the reverse of the replacements would occur but after a little testing, it seems that code has been added to handle both scenarios. It still feels clunky, at best. Take the following example:

The 1st one resolves correctly with dashes in the URL. Removing the dashes results in a 404

The 2nd one resolves with spaces and dashes. The LinkManager generates URLs with dashes.

generates URLs with dashes. The 3rd one ONLY resolves exactly how it is written, with the mix of spaces and dashes. The LinkManager generates URLs with all dashes. So test-item—with-dashes. Uh oh. 404!

So I can’t even link to the item using the RTE.

But why was I able to create an item with dashes? Because the InvalidItemNameChars setting has not been updated to disallow dashes. But disallowing dashes means I can’t install WFFM since the Item names contains dashes… It’s all in my post.

But not just this module, potentially many other Shared Source modules available through the Marketplace. Don’t forget your items in the media library either!

And guess what else? Languages! You know those 4 character language/region codes with dashes in the middle? Disallowing dashes means you can add those either!

Upgrading? Don’t already have a solution in place to replace spaces with dashes? That’s a stinger. Also don’t forget that since Sitecore 7.2 those encodes also apply to the Media Library and thus any Media Items with dashes in the name suffer the same fate.

So, the solution for most of us will be pretty simple:

<encodeNameReplacements> <replace mode="on" find=" " replaceWith="-"> <patch:delete /> </replace> </encodeNameReplacements>

Yup, good old trusty config overrides.