Copied to clipboard

Flag this post as spam?

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


  • fabbau 18 posts 108 karma points
    Oct 07, 2020 @ 15:17
    fabbau
    0

    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:

    www.mysite.com/blog/?category=Santé
    

    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 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 21, 2020 @ 15:50
    Lee Kelleher
    0

    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: https://our.umbraco.com/documentation/Reference/Config/umbracoSettings/#requesthandler

    Example config would look like this...

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

    Although I believe the toAscii option should cover it.

    Hope this helps.

    Cheers,
    - Lee

  • fabbau 18 posts 108 karma points
    Oct 22, 2020 @ 09:07
    fabbau
    0

    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 3945 posts 15163 karma points MVP 10x admin c-trib
    Oct 22, 2020 @ 10:59
    Lee Kelleher
    0

    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.

    Cheers,
    - Lee

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies