London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

K Khan
Sep 19, 2024
  728
(1 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

Mark Stott
Mark Stott Sep 20, 2024 08:18 AM

Hello Khan,

It's worth noting that the builtin Optimizely behaviour is in alignment with the current RFC 3986 URI (Uniform Resource Identifier) specification.  I've had issues before with non-compliant characters within URLs and iterpretation by the browser and documentation platforms with confusion of encoding.  In these cases I would personally recommend against this.

K Khan
K Khan Sep 20, 2024 08:25 AM

Make sense, thanks for sharing.

Please login to comment.
Latest blogs
Creating a Dropdownlist in Optimizely CMS: Populate ISelectionFactory with values from another block's properties

Create a Block to hold selection options using EPiServer.Cms.Shell.UI.ObjectEditing.EditorDescriptors; using EPiServer.PlugIn; using EPiServer.Shel...

sunylcumar | May 12, 2025

Opal AI available in Optimizely CMS (SaaS)

Use Opal AI to translate your content!

Tomas Hensrud Gulla | May 12, 2025 |

Opal AI available in Optimizely CMS (SaaS)

Use Opal AI to translate your content!

Tomas Hensrud Gulla | May 12, 2025 |

Get Up to Speed with Optimizely Opal: Quick Start Resources

Exciting New Feature Updates to Optimizely Opal: Elevating Your Product Experience We're thrilled to announce the launch of massive feature updates...

Patrick Lam | May 9, 2025