Generation of URL segment for content

Vote:
 

Hello

When a page is created an URL is auto-generated that changes ø to o. Is there any way to change this behaviour so that ø becomes oe?

Thanks in advance.

Regards,
Benjamin

#200504
Jan 14, 2019 14:50
webtoolsoffers - Jul 15, 2019 12:14
I am also facing this type of problem on my website Webtoolsoffers and I resolve this problem through this post.
Vote:
 

Hi Benjamin,

I'd probably go with implementing a custom IUrlSegmentGenerator, one that still uses the default functionality:

internal class CustomUrlSegmentGenerator : IUrlSegmentGenerator
{
    private readonly IUrlSegmentGenerator _urlSegmentGenerator;

    public CustomUrlSegmentGenerator(IUrlSegmentGenerator urlSegmentGenerator)
    {
        _urlSegmentGenerator = urlSegmentGenerator;
    }

    public string Create(string proposedSegment, UrlSegmentOptions options)
    {
        // Replace ø whilst maintaining case of the original
        proposedSegment = Regex.Replace(proposedSegment, "ø", match => char.IsUpper(match.Value[0]) ? "OE" : "oe", RegexOptions.IgnoreCase);

        return _urlSegmentGenerator.Create(proposedSegment, options);
    }

    public bool IsValid(string segment, UrlSegmentOptions options)
    {
        return _urlSegmentGenerator.IsValid(segment, options);
    }
}

and the initialization module:

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class UrlSegmentGeneratorInitializer : IConfigurableModule
{
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        context.Services.Intercept<IUrlSegmentGenerator>(
            (locator, defaultUrlSegmentGenerator) => new CustomUrlSegmentGenerator(defaultUrlSegmentGenerator));
    }
    public void Initialize(InitializationEngine context) { }
    public void Uninitialize(InitializationEngine context) { }
}
#200509
Jan 14, 2019 16:49
Vote:
 

@Aniket: As far as I can see doesn't your code do something entriely different?

It wouldn't make any difference to the default segment for a page, but would it fact mean that if the user entered the URL:

/en/hellø

it would try to route it to:

/en/helloe

#200511
Jan 14, 2019 17:14
Vote:
 

Hi Jake,

You are right. I misread the question. Deleting my comment to avoid confusion.

Aniket

#200512
Jan 14, 2019 17:17
Vote:
 

Thank you for your answers!

#200540
Jan 15, 2019 12:23
Vote:
 

Thanks Jake, this helped me with a similar situation, replacing double hypens from generated urls.

while (proposedSegment.Contains("--"))
{
    proposedSegment = proposedSegment.Replace("--", "-");
}
#205341
Jul 05, 2019 17:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.