Redirect old SharePoint sites to new SharePoint sites with deep URLs using IIS rewrite module and rewrite map

This is a fairly common scenario when we move from one SharePoint farm to another SharePoint farm with a new URL or consolidate multiple Legacy farms into one single SP farm and some restructuring also happens as it relates to what content goes to which web apps / site collections.

Before we begin make sure you have downloaded and installed the URL Rewrite extension from Microsoft for IIS. It can be found here. One thing to remember here is if you are using multiple SSL sites and want to have the redirect service on single IIS web server then you would need multiple internal IPs to bind those SSL certs to.

I will show you here in this example how we can handle a scenario where 2 SharePoint farms were migrated to single farm and redirects were configured.

So in this scenario we will go form http://teamsites.contoso.com in one farm and http://sharepoint.contoso.com in another farm to http://teamsites.fabrikam.com. Assuming we migrated http://teamsites.contoso.com sites from a SP 2007 environment to SP 2013 site http://teamsites.fabrikam.com and http://sharepoint.contoso.com from SP 2010 to SP 2013 site.

A visual table record is always handy to relate with the final outcome for your code. This mapping table shows our desired scenario for redirecting each URL.

URL Mapping Table

[table width=”500″ colwidth=”50|50″ colalign=”left|left”]
Old URL,New URL
http://teamsites.contoso.com,http://teamsites.fabrikam.com
http://teamsites.contoso.com/sites/HR,http://teamsites.fabrikam.com/sites/HR
http://teamsites.contoso.com/sites/Sales,http://teamsites.fabrikam.com/sites/Sales
http://sharepoint.contoso.com,http://teamsites.fabrikam.com/sites/sharepoint
http://sharepoint.contoso.com/sites/Team1,http://teamsites.fabrikam.com/sites/Team1
[/table]

Now assuming you have a dedicated IIS Web Server instance where you will run this redirect service from we will proceed to our next steps.

Create two websites in IIS and for this Demo I will call them “TeamRedirect” and “SharePointRedirect”. You will be asked to place them in a directory. Make sure that directory is empty and not being used by any other service or for any other purpose. By default the directory is going to be empty. We are now going to place the following two files in both sites empty directory: web.config and maps.config

Code for Web.config for “TeamRedirect” website: (Make sure to edit the bindings for this site to listen to teamsites.contoso.com on port 80)

Note: The URL parameter in Action Type tag is responsible for the base URL for all target URLs, hence the missing “/” in the below mapping table for value pair. {C:1} is where the value pair from the map gets written to.

Code for maps.config for “TeamRedirect” website:

Note: The default value will send the user to root site including any other URL that does not match.

Code for Web.config for “SharePointRedirect” website: (Make sure to edit the bindings for this site to listen to sharepoint.contoso.com on port 80)

Code for maps.config for “SharePointRedirect” website:

Note: Check the mapping table and note the default URL difference.

And that is it ! You are all set. Make sure your DNS entries point to this redirect service for the OLD SP sites.

I would also like to add another frustration I had to go through while testing this. All browsers cache permanent redirects differently and cannot be removed by clearing your normal cache from the browser. Just google the steps for each browser type and version you are using in case you want to revert back to old DNS entry (very helpful if testing via local host entry).

I have personally tested the rewrite map with 1200 or so entries and it has worked like a charm. If anyone tests this with more entries do let me know I would love to hear if that works well enough too. Microsoft does not document any hard limit for the number of entries this map can actually have.

Jasjit Chopra is a MS Cloud Architect with strong background in SharePoint, Office 365 and Azure. As a SharePoint expert he has worked with many multinational clients including HP, Avanade, Accenture, Unistar Nuclear Energy, Warner Music Group, Inventiv Health and iHeartMedia. Jasjit holds a Masters of Business Administration in Technology and Management from CERAM, Sophia Antipolis, France. Having worked for different clients across the United States Jasjit has gained insight knowledge on Business Processes for the State Government and Manufacturing, Nuclear, Pharmaceutical and Music industries.

8 thoughts on “Redirect old SharePoint sites to new SharePoint sites with deep URLs using IIS rewrite module and rewrite map

  1. Hi Jasjit,

    I am working on SharePoint migration from 2010 to 2013, there are 50 site collections i have migrated 20 site collections to 2013.

    Here am looking for URL redirection from 2010 farm to 2013 farm for the completed site collection.

    The only change in url is

    Ex:

    2010 URL : http://myoldhost/sites/welcome (which has many inner level subsites, so any sites/subsites has to be redirected respective 2013 site/subsites)

    2013 URL : http://mynewhost/sites/welcome

    Please give your suggestion or steps to achieve the above scenario.

    I read the one of your article/post which is using URL rewrite 2.0 module in IIS, am struggling to implement that so please help me on that.

    Thanks in advance

    Regards,
    Prakash

  2. Hi Jasjit,

    I am working on a SharePoint on premise to SharePoint online/O365 project. We are selectively migrating sites.I need to configure redirection to make sure the old bookmarks/document references works after the migration.The challenge here is SPO only allows /teams or /sites managed paths and we have used many different managed paths on the existing on premise instance. Can you please provide me some suggestions on this.

    For example on premise I have http://sharepoint/corp/it/ this needs to be redirected to https://.sharepoint.com/teams/

    Thanks,
    Srini

    1. Hi Srini,

      I see your point. You can still maintain each single entry or write complex redirect rules to make the relative paths work. I have not tried this but it is definitely possible within rewrite module within IIS.

      Another option for you could be to check the firewall rewrite features. Some firewalls like F5 have robust rewrite options which can help you out here.

      I will surely write a blog post to cover advanced scenarios and relative URL redirects in future, but I cam preoccupied right now.

      Regards,
      Jasjit

  3. Hi Jasjit,

    Hope you are doing well.

    The above mentioned scenario is working perfectly where only Domain name changed (manages path and site collection name will remain same)

    In my case – IA is completely changed
    OLD URL New URL
    http://teamsites.contoso.com/Department/HR
    http://teamsites.fabrikam.com/sites/Dept-HR

    http://sharepoint.contoso.com/Project/Team1
    http://teamsites.fabrikam.com/sites/Project-Team1

    Could you please suggest whether IIS Http Redirect or NLB redirect module will also help here?
    As per my understanding in such case only custom redirect approach will work.
    eg.
    1. Write a javascript code in your old site’s master page to redirect to new page
    2. Custom HTTP Module

    1. Yes it can help in your scenario. You will have to write custom rules there and then publish them in IIS. This will be a bit tricky but definitely possible.

      In such a scenario I would recommend using a DB or a list based approach that acts as source of table mapping of new URLs and then redirects the user.

Leave a Reply