SEO%20Friendly%20URLs – Watch out, it’s a trap!

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:

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

It was there in the release notes:…/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!

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:

SEO Friendly Items

  • 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.
  • 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:

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

Yup, good old trusty config overrides.


  1. Andreas Gehrke (@agehrke) · February 29, 2016

    LOL. I implemented the exact same on a new Sitecore 8.0 solution some months ago, of course by also adding dash to InvalidItemNameChars setting. Got hit by it last week, as Sitecore failed install Sitecore Powershell Extensions. Dooh.
    How come ProposeValidItemName() isn’t used when installing packages? Most likely because package authors would no longer be able to rely on retrieving items by path/name. Argh!

    • jammykam · June 13, 2016

      Just saw your message, sorry! I think as you state, it may break queries on code! The WFFM module also used to fail install due to dashes in Item Names. Not sure if they have fixed that yet either!

  2. I have run into this also. Annoying 🙂
    But what is your take on solving this easiest/best, if not using encodeNameReplacements?

    • jammykam · June 13, 2016

      I’ve been using the Rules Engine module I blogged about previously. I have some updates to the code which I need to push out, but essentially deal with the problem at source and then not worry about any transformations of any kind.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s