Copied to clipboard

Flag this post as spam?

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


  • Adriano Fabri 459 posts 1602 karma points
    Jul 15, 2016 @ 12:42
    Adriano Fabri
    0

    Umbraco 7 and URLRewriting

    Hi, I need to rewrite an URL like this

    http://www.example.com/test-data/italia/?region=abruzzo
    

    in a friendlier one like this

    http://www.example.com/test-data/italia/abruzzo
    

    I tried some test but I haven't found the correct configuration.

    The last (wrong) test has been:

    <add
        name="Filter Data Rewrite"
        rewriteUrlParameter="ExcludeFromClientQueryString"
        ignoreCase="true"
        virtualUrl="~\/test-data\/italia\/\?region=[a-z]"
        destinationUrl="~\/test-data\/italia\/${region}" />
    

    Can anyone help me to write right url rewriting code?

    Thank you in advance Adriano

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Jul 15, 2016 @ 19:10
    Søren Kottal
    100

    If I understand your intentions correctly, then you have confused the virtualUrl with the destinationUrl. Besides that, your regex for the region parameter is wrong (and you should consider allowing some more characters than just a-z, /test-data/italia/abruzzo2 wont work ie.)

    Try this

    <add
        name="Filter Data Rewrite"
        rewriteUrlParameter="ExcludeFromClientQueryString"
        ignoreCase="true"
        virtualUrl="^\/test-data\/italia\/([a-z]*)$"
        destinationUrl="~\/test-data\/italia\/\?region=$1" />
    

    So, the virtualUrl (the one the user types) must start with /test-data/italia/ and end with an infinite amount of letters ranging from a-z. The last part is grouped in paranthesises, so we can reference that in the destinationUrl.

    The destinationUrl is then /test-data/italia/?region=[the last part of the virtualUrl].

  • Adriano Fabri 459 posts 1602 karma points
    Jul 19, 2016 @ 07:43
    Adriano Fabri
    0

    OH...I'm sorry, I mistyped. I swapped the virtualurl with the destinationurl. :-)

    Thank you Adriano

Please Sign in or register to post replies

Write your reply to:

Draft