K Khan
Sep 19, 2024
  37
(0 votes)

keep special characters in URL

When creating a page, the default URL segment validation automatically replaces special characters with their standard equivalents (e.g., "ä" is replaced with "a"). However, some clients may require these special characters to remain intact in URLs for non-English versions of their website.

var validChars = "ü ö ä ß ó ñ á á é í ó ő ú ü ñ"; 

For CMS 12

//Startup.cs
services.Configure<UrlSegmentOptions>(config => {
    config.SupportIriCharacters = true;
    config.ValidCharacters = @"A-Za-z0-9\-_~\.\$" + validChars;
}); 

For CMS 11

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class UrlSegmentConfigurationModule : IConfigurableModule
{
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        var validChars = "ü ö ä ß ó ñ á á é í ó ő ú ü ñ"; 
        context.Services.RemoveAll<UrlSegmentOptions>();
        context.Services.AddSingleton<UrlSegmentOptions>(s => new UrlSegmentOptions
        {
            SupportIriCharacters = true,
            ValidCharacters = @"\p{L}0-9\-_~\.\$" + validChars
        });
    }

    public void Initialize(InitializationEngine context){}

    public void Uninitialize(InitializationEngine context) { }
}

References:

Sep 19, 2024

Comments

Please login to comment.
Latest blogs
Streamlining Marketing Success: The Benefits for Optimizely One with Perficient

As an Optimizely expert, I eagerly anticipate this time of year due to the exciting Optimizely events happening worldwide. These include Opticon, t...

Alex Harris - Perficient | Sep 17, 2024 | Syndicated blog

Creating an Optimizely Addon - Packaging for NuGet

In   Part One   and   Part Two   of this series; I covered topics from having a great idea, solution structure, extending the menus and adding...

Mark Stott | Sep 16, 2024

Optimizely CMS and weekly updates

Learn how reporting bugs in Optimizely CMS not only helps improve the platform but also benefits you and the entire user community.

Tomas Hensrud Gulla | Sep 12, 2024 | Syndicated blog