evont-software.com

Email: info@evont-software.com

Guide to Managing Website Redirects: Best Practices for Mysite

Category:Administration
Date:
Author: Mathias Osterkamp

Redirect Mysite to a modern Page

Goal

SharePoint 2019 OnPremise has still the classic MySite. To support a modern page you could build it on top of the default MySite host, but this is not the best way. With a redirect based solution you don't change anything to existing code. Just build your new MySite features on a new page on a different WebApplication and SiteCollection based on modern theme. All important links should be redirected.

Possible Solutions

To get your MySite pages redirected you face one problem. It is not only the default.aspx on MySite Host, there are several more pages especial on the user generated personal site collections. (ex. https://mysite.contoso.com/personal/<>/...)

IIS Redirect

Best solution is to use the features of IIS URL Rewrite Module. It has to be installed first on every SharePoint frontend server:

URL Rewrite Module 2.1: https://www.iis.net/downloads/microsoft/url-rewrite

Advantages:

Disadvantages:

  • No permission based redirect, you had to implement a permission based logic on target page

HTTP Handler

With a Http Handler you can access every request in IIS to add some custom logic.(Sample)

Code from stack overflow to demonstrate the basic solution link :

1<add name="CustomHttpModule" type="CustomHttpModule.HttpModuleImplementation, CustomHttpModule" />
2using System;
3using System.Web;
4using System.Web.UI;
5using System.Configuration;
6using Microsoft.Practices.EnterpriseLibrary.Data;
7using System.Data;
8
9namespace CustomHttpModule
10{
11 public class HttpModuleImplementation : IHttpModule
12 {
13 #region IHttpModule Members
14
15 public void Dispose()
16 {
17
18 }
19
20 public void Init(HttpApplication context)
21 {
22 if (context == null)
23 throw new ArgumentNullException("Context == null");
24
25 context.AuthorizeRequest += new EventHandler(this.ProcessRequestHandler);
26 }
27 #endregion
28
29 private void DummpRequest(object sender, EventArgs e)
30 {
31 }
32 //first check that user.identity record exist in database
33 //If not then forward user to User registration page
34 private void ProcessRequestHandler(object sender, EventArgs e)
35 {
36 try
37 {
38 HttpApplication context = (HttpApplication)sender;
39 string strAbsoluteUri = context.Request.Url.AbsoluteUri.ToLower();
40 //check if request is accessing aspx page
41 if (strAbsoluteUri.Substring(strAbsoluteUri.Length - 5, 5).Contains(".aspx"))
42 {
43 string userName = context.User.Identity.Name;
44 //replace Test Module with DB call to validate user data
45 if (!CheckUserInDb(userName))
46 {
47 if (!strAbsoluteUri.Contains("mypage.aspx"))
48 redirectToRegistrationPage(context);
49 }
50 }
51 }
52 catch (Exception ex)
53 {
54 }
55 }
56 private void redirectToRegistrationPage(HttpApplication context)
57 {
58 context.Response.Redirect("http://" + context.Request.ServerVariables["HTTP_HOST"].ToString() + "Regpage.aspx", false);
59 }
60
61 private bool CheckUserInDb(string userName)
62 {
63 return true;
64 }
65 }
66}


Advantages:

  • Support for complex rules and permission based redirects

Disadvantages:

  • SharePoint Solution needed
  • A lot of work to make good implementation
  • Rules have to be stored
  • Untested
  • Slow

Modify Pages

You also can modify each target page to add some redirect logic for example:

<meta http-equiv="refresh" content="0;url=https://sharepoint.contoso.com/Sites/Home.aspx" />

Advantages:

  • Modify only specific pages

Disadvantages:

  • You can not modify system pages like "Edit Profile"
  • No easy way to redirect personal pages

Pages for consideration

Following pages should be under consideration:

Title

Regex

Description

DefaultMySite

^default.aspx

About me

PersonMySite

person.aspx

Activities

MyPeopleMySite

mypeople.aspx

Newsfeed entries

Documents

personal/\w*/_layouts/15/onedrive.aspx

Onedrive documents

Blog

personal/\w*/Blog/*

Personal blog

Personal_Default

personal/\w*/default.aspx

Personal newsfeed

AddApp

personal/\w*/_layouts/15/addanapp.aspx

Add apps to mysite

Newsbweb

personal/\w*/_layouts/15/newsbweb.aspx

Create new subsites

Sitemanager

personal/\w*/_layouts/15/sitemanager.aspx

Site Manager

SocialSites

personal/\w*/Social/Sites.aspx

Followed sites

FollowedDocumentsSites

personal/\w*/Social/FollowedContent.aspx

Followed documents

SharePointHome

_layouts/15/sharepoint.aspx

Followed site activities

Quicklinks

_layouts/15/MyQuickLinks.aspx

Quick links

HashTags

_layouts/15/HashTagProfile.aspx

Followed HashTag Newsfeeds

IIS Redirect Rules

What also should work is to redirect other accounts. So we still keep url parameters (default for iis rules):

.../person.aspx?accountname=<> > .../Sites/Home.aspx?accountname=<>

You can also create a url parameter to stop redirect, if you like still have an access possibility. For example https://mysite.contoso.com/default.aspx?stopredirect=1 :

<conditions>
<add input="{QUERY_STRING}" pattern="stopredirect=1" negate="true" />
</conditions>

Here is a list of important rules:

1<rule name="Redirect_Default_MySite" stopProcessing="true">
2 <match url="^default\.aspx" />
3 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
4</rule>
5<rule name="Redirect_Person_MySite" stopProcessing="true">
6 <match url="person\.aspx" />
7 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
8</rule>
9<rule name="Redirect_MyPeople_MySite" stopProcessing="true">
10 <match url="mypeople\.aspx" />
11 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
12</rule>
13<rule name="Redirect_OneDrive" stopProcessing="true">
14 <match url="personal\/\w*\/_layouts/15/onedrive\.aspx" />
15 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
16</rule>
17<rule name="Redirect_Blog" stopProcessing="true">
18 <match url="personal\/\w*\/Blog\/\*" />
19 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>
20</rule>
21<rule name="Redirect_Personal_Default" stopProcessing="true">
22 <match url="personal\/\w*\/default\.aspx" />
23 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>
24</rule>
25<rule name="Redirect_AddApp" stopProcessing="true">
26 <match url="personal\/\w*\/_layouts/15/addanapp\.aspx" />
27 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>
28</rule>
29<rule name="Redirect_Newsbweb" stopProcessing="true">
30 <match url="personal\/\w*\/_layouts/15/newsbweb\.aspx" />
31 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>
32</rule>
33<rule name="Blocken_Sitemanager" stopProcessing="true">
34 <match url="personal\/\w*\/_layouts/15/sitemanager\.aspx" />
35 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>
36</rule>
37<rule name="Redirect_SocialSites" stopProcessing="true">
38 <match url="personal\/\w*\/Social/Sites\.aspx" />
39 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
40</rule>
41<rule name="Redirect_FollowedDocumentSites" stopProcessing="true">
42 <match url="personal\/\w*\/Social/FollowedContent\.aspx" />
43 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
44</rule>
45<rule name="Redirect_SharePointHome" stopProcessing="true">
46 <match url="_layouts/15/sharepoint\.aspx" />
47 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
48</rule>
49<rule name="Redirect_Quicklinks" stopProcessing="true">
50 <match url="_layouts/15/MyQuickLinks\.aspx" />
51 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
52</rule>
53<rule name="Redirect_HashTags" stopProcessing="true">
54 <match url="_layouts/15/HashTagProfile\.aspx" />
55 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />
56</rule>


More documentation from Microsoft here: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module