Search code examples
url-rewritingumbraco7

Best way to redirect entire folder of content in Umbraco


We're going to be redeveloping a large site (12K+ pages, 300K uniques per month). Plan is to use Umbraco 7 in a load balanced scenario.

However, on the old site we have a lot of content such as: www.example.com/folder1/folder2/folder3/brown-fox.aspx

In the new site we're thinking of changing the structure somewhat to something like: www.example.com/folder1/brown-fox.aspx

So what would be the best way to redirect entire folder paths? The end of the Url (brown-fox.aspx) will stay the same, just the folder structure.

I know I could add a URL Rewrite rule for each page but that would be very unmanageable very quickly and with that many potential redirects I'm worried about performance.

Any ideas much appreciated.


Solution

  • I've found that the URL Rewrite Module for IIS is the best option for situations like these. It's fast and powerful.

    I think what you're looking for is something like this in your web config. You would then create a similar rule for each group of folders that need redirecting.

    <rule name="New Folder Structure" stopProcessing="true">
        <match url="^folder1/folder2/folder3/(.*\.aspx)$" />
        <action type="Redirect" url="/folder1/{R:1}" 
            appendQueryString="true" redirectType="Permanent" />
    </rule>
    

    Alternatively, if you don't intend to serve anything deeper than /folder1/, you can have one rule to... rule them all...

        <rule name="New Folder Structure" stopProcessing="true">
          <match url="^folder1/(.*)/(.*\.aspx)$" />
          <action type="Redirect" url="/folder1/{R:2}"
              appendQueryString="true" redirectType="Permanent" />
        </rule>
    

    Full examples etc. can be found here.