Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • fabbau 20 posts 110 karma points
    Oct 07, 2020 @ 15:17

    Remove special characters in URL query parameter

    Hi all,

    there is a blog page on our umbraco instance. The blog entries have some taxonomies and sometimes there are special chars like "é" in it. If a user now filters for blog entries associated with a taxonomy, the taxonomy string gets added to the URL as query parameter

    Example URL:é

    For better SEO results the client now wants to replace those special chars with normal ones.

    Any idea on how to achieve this?

    Thank you guys.

  • Lee Kelleher 3993 posts 15621 karma points MVP 12x admin c-trib
    Oct 21, 2020 @ 15:50
    Lee Kelleher

    Hi fabbau,

    Sorry that no one else had replied to you in the past 2 weeks. Hopefully you were able to resolve the issue.

    If not, then there is a option in the "/config/umbracoSettings.config" that handles special characters in the URL.

    There are more options in the documentation here:

    Example config would look like this...

      <!-- this ensures that all url segments are turned to ASCII as much as we can -->
      <urlReplacing toAscii="try">
        <char org="é">e</char>

    Although I believe the toAscii option should cover it.

    Hope this helps.

    - Lee

  • fabbau 20 posts 110 karma points
    Oct 22, 2020 @ 09:07

    Thanks for the answer Lee,

    This is what I already have in place. But the URL replacing rules only applies to URLs itself and not to query parameters. Those parameters remain unchanged.

  • Lee Kelleher 3993 posts 15621 karma points MVP 12x admin c-trib
    Oct 22, 2020 @ 10:59
    Lee Kelleher

    Doh! It would help if I read your question properly, apologies!

    Since I'm not sure how you are currently implementing the categories and filtering logic, there are a couple of ways to you could approach it.

    One way would be to sanitize the category value at the point when it's rendered, e.g. in the Razor view, something like...

    <a href="/blog/[email protected]()">@value</a>

    *obviously I'm not sure how you're actually doing this.

    Note, the ToUrlSegment() extension method is what Umbraco uses to generate the "URL safe" name of a node... you can use it on any string.

    That would make the URLs to use ASCII characters.

    Then on the filtering side... it'd be a case of however you are doing the logic, to apply the same sanitization, something like...

    var category = Request.QueryString["category"];
    var items = Model.Children.Where(x => x.Category.ToUrlSegment() == category);

    *this is just pseudo-code (written off the top of my head). Of course, I'm not sure how you're actually doing the filtering.

    Hope this helps.

    - Lee

Please Sign in or register to post replies

Write your reply to: