Copied to clipboard

Flag this post as spam?

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


  • Srdjan Lukic 34 posts 166 karma points
    May 27, 2015 @ 00:51
    Srdjan Lukic
    0

    UrlRewriting with and without trailing slash

    Greetings!

    First of all the Umbraco version that I'm currently working on is : v 4.7.2 .

    My clint wants to redirect www.domain.com/summer/  to www.newdomain.com/

    So I added following line into UrlRewriting.config 

    <add name="rewrite237" 
    redirectMode="Permanent"
    redirect="Domain"
    ignoreCase="true"
    rewriteUrlParameter="IncludeQueryStringForRewrite"
    virtualUrl="www.domain.com/summer/"
    destinationUrl="www.newdomain.com/" />

    But that doesn't include www.domain.com/summer , so if I change the <add> to:

    <add name="rewrite237" 
    redirectMode="Permanent" 
    redirect="Domain" 
    ignoreCase="true" 
    rewriteUrlParameter="IncludeQueryStringForRewrite" 
    virtualUrl="www.domain.com/summer" 
    destinationUrl="www.newdomain.com/" />

    Then it works with www.domain.com/summer & www.domain.com/summer/  but then I hit another issue. Inside umbraco. My client have another node called  summer14.  so www.domain.com/summer14 . Now since I've added my last update to <add> the summer14 node is also being redirected. and the end url for some reason is: www.newdomain.com/14/ 

    Is there a way to tell UrlRewriting.config to only redirect summer and summer/  ?

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    May 27, 2015 @ 01:12
    Chriztian Steinmeier
    0

    Hi Srdjan,

    If you end the RegEx with a dollar sign, it will only match the end of the string, so add a $ on the end and see how that works.

    /Chriztian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 31, 2016 @ 12:39
    Chriztian Steinmeier
    0

    Hi Srdjan,

    Just had a need to figure this out for realz :-)

    So adding [/] matches a single slash - adding a ? to make it optional and then finally put a $ on the end to match the end of the string, essentially matching an optional trailing slash:

    <add name="rewrite237"
       redirectMode="Permanent"
       redirect="Domain"
       ignoreCase="true"
       rewriteUrlParameter="IncludeQueryStringForRewrite"
       virtualUrl="www.domain.com/summer[/]?$"
       destinationUrl="www.newdomain.com/"
    />
    

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft