2
votes

This seems trivial, yet I can't find an existing answer online...

I'm using Sitecore and I have configured it to use an item's display name to generate its url (using the "useDisplayName" setting).

Now, when I have an item with display name "Test, with commä" I would expect Sitecore's LinkManager to provide me with a valid URL:

/nl-NL/ContentPage/Test%2C-with-comm%C3%A4

However, it gives me an URL with the invalid characters not encoded:

/nl-NL/ContentPage/Test,-with-commä

Now I know I can make exceptions for specific characters, but that's not the point. I'd like Sitecore to remove ANY illegal URL characters with their encoded counterparts.

Isn't there a setting or a simple way to achieve this?

1

1 Answers

2
votes

Unfortunately Sitecore does not support encoding url parts in a way you want it.

And encodeNames="true" only tells Sitecore to use what is configured in encodeNameReplacements setting.

You have 2 options:

  1. Contact with Sitecore Support and tell them about this bug.
  2. Override LinkProvider class and encode urls:
public class CustomLinkProvider : Sitecore.Links.LinkProvider
{
    public override string GetItemUrl(Item item, UrlOptions options)
    {
        var itemUrl = base.GetItemUrl(item, options);

        // your code to encode the url

        return itemUrl;
    }
}
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
  <linkManager>
    <providers>
      <add name="sitecore">
        <patch:attribute name="type">My.Assembly.Namespace.CustomLinkProvider,My.Assembly</patch:attribute>
      </add>
    </providers>
  </linkManager>
</sitecore>
</configuration>