Some of the links in my Umbraco site have swedish characters in the url. I wonder if there is an easy way to control how these characters show up in the links? For now ö -> oe, å -> aa and ä -> ae. I would like ö -> o, å -> a, ä -> a.
I can use Replace to change the url:s but then the links won´t work. Is it possible to do some setting in Umbraco to get this to work?
I solved this problem with a CustomUrlSegmentProvider.
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Strings;
namespace RoutingDocs.SegmentProviders;
public class CustomUrlSegmentProvider : IUrlSegmentProvider
{
private readonly IUrlSegmentProvider _provider;
public CustomUrlSegmentProvider(IShortStringHelper stringHelper)
{
_provider = new DefaultUrlSegmentProvider(stringHelper);
}
public string? GetUrlSegment(IContentBase content, string? culture = null)
{
var updatedName = content.Name?
.Replace("ö", "o")
.Replace("å", "a")
.Replace("ä", "a")
.Replace("Ö", "O")
.Replace("Å", "A")
.Replace("Ä", "A");
var segment = _provider.GetUrlSegment(content, culture);
return segment?.ToLowerInvariant();
}
}
using Umbraco.Cms.Core.Composing;
namespace RoutingDocs.SegmentProviders;
public class CustomUrlSegmentComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.UrlSegmentProviders().Insert
Swedish characters in url
Some of the links in my Umbraco site have swedish characters in the url. I wonder if there is an easy way to control how these characters show up in the links? For now ö -> oe, å -> aa and ä -> ae. I would like ö -> o, å -> a, ä -> a.
I can use Replace to change the url:s but then the links won´t work. Is it possible to do some setting in Umbraco to get this to work?
I solved this problem with a CustomUrlSegmentProvider.
using Umbraco.Cms.Core.Strings;
namespace RoutingDocs.SegmentProviders;
public class CustomUrlSegmentProvider : IUrlSegmentProvider { private readonly IUrlSegmentProvider _provider;
}
namespace RoutingDocs.SegmentProviders; public class CustomUrlSegmentComposer : IComposer { public void Compose(IUmbracoBuilder builder) { builder.UrlSegmentProviders().Insert
In Program.cs:
Remember to refresh the Umbraco-cache and re-publish all content.
Thanks for sharing this!
is working on a reply...