Copied to clipboard

Flag this post as spam?

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


  • Christina 127 posts 390 karma points notactivated
    Sep 03, 2021 @ 14:21
    Christina
    0

    Redirect url with category and two nodes

    Hi I would like som help on best practice.

    I have a main site with two nodes winter / summer. I want to redirect 301 the old url from mydomain.com/winter/ or -> mydomain.com/en/winter/ and mydomain.com/summer/ or -> mydomain.com/en/summer/

    I have tried Skybruds.redirect but I can't use the full url, because It's not allowed. The path is coming from node. Is there any package that I can use or do I have to make redirects url in web.config? It's a lot of url:s in different sub categories

    Many thanks! Christina

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Sep 04, 2021 @ 10:01
    Marc Goodson
    0

    Hi Christina

    This sounds like a job for IIS redirect in your Web.Config (if I've understood correctly) because it seems like 'all the urls for winter and summer will be the same, but just with /en/ put in front'. With an IIS redirect rule you can 'pattern match' so you only need to specify a single rule to match all the redirects - whereas with Skybrud or similar you would need to have one entry for each url, to map to it's new url, which might be tons of Urls! (and the database access might be slow)

    Now the thing with IIS redirects, are they are a bit fiddily and you almost always get it wrong first time and match too much or too little, or miss the closing slash or whatever, but once you have the right rules in, they will be very fast, as they will action in IIS, before Umbraco gets involved trying to handle the request.

    Lots of info here: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    but what you might end up with is two rules:

    <rule name="Redirect Winter">
      <match url="^winter(.*)$" />
      <action type="Redirect" url="/en/{R:0}" redirectType="Permanent" />
    </rule>
    

    Where {R:0} is a 'back capture' which means the 'whole original url'

    so a url like

    winter/about-winter/anything

    will become

    /en/winter/about-winter/anything

    and then duplicate the same rule for summer:

    <rule name="Redirect Summer">
      <match url="^summer(.*)$" />
      <action type="Redirect" url="/en/{R:0}" redirectType="Permanent" />
    </rule>
    

    Anyway, it's regexes as I say, so probably never works first time! but hopefully gives you the insight that if you play around with these two rules, it will match and redirect all the urls in one place.

    regards

    Marc

  • Christina 127 posts 390 karma points notactivated
    Sep 06, 2021 @ 06:12
    Christina
    0

    Hi Marc and thanks for your help and comments. I think it's tricky with redirect rules but I get to learn more about regex :) But I realize this is how I need to solve the problem.

    Thanks again for your support Christina

Please Sign in or register to post replies

Write your reply to:

Draft