1

We are migrating from SP 2013 to SP 2016. There are multiple sub-sites under the main site and further sub-sites under those sub-sites. The users may have bookmarked specific libraries and lists from the old URL and they need to be routed to the main page of the sites with the new URL. For example,

OLD URL:

https://abc/subsite1/subsite2/subsite3

NEW URL:

https://xyz/subsite1/subsite2

Now the sub-sites in the SP 2013 are inheriting the master page from the Subsite1 level. If it was a simple redirect where every site had their own master page I could have used JavaScript like:

location.href="[new url]"

and be done with it. Now I believe I need if-else statements in the sub-site 1 master page to check for what URL the user is using and then redirect it.

I have tried the following:

if(location.href=='https://abc/subsite1/subsite2/subsite3/')
{
 location.href='https://xyz/subsite1/subsite2';
}

else if(location.href=='https://abc/subsite1/subsite2/subsite3/')
{
 location.href='https://xyz/subsite1/subsite2';
}

The issue is user may have bookmarked a list from abc and the check would fail. How do I just check for the path till sub-site2 with JavaScript?

I am open to other ways of achieving this in SharePoint as well.

2

You could split the path to an array so you could check the sub site url(path).

var pathArray = window.location.pathname.split('/');
var Location = pathArray[index];
0

I would recommend you handle this at IIS level rather than implement something in masterpage. You can implement rule based redirect using URL rewrite module, and supports complex pattern matching (regex). As you migrate content to new environment, you can keep adding new rules based on your new information architecture.

0

To help the people facing the same problem, this is how i solved the issue:

Since I wanted to check for the sub-sites in the URL and redirect accordingly. I used the following JavaScript code:

if(window.location.href.indexOf('sub-site/sub-site/sub-site')>-1)
    {
        location.href='<URL where you want to route>';
    }   

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.