How to Create a Redirect in SharePoint Online?

Requirement: Create a redirect in SharePoint Online.

How to Redirect a SharePoint Online page to a different URL?

Redirects are a great way to automatically redirect visitors to another page or forward users to other sites from SharePoint Online when they try to access a page that doesn’t exist or has been moved. This can be helpful if you want to reorganize your website or have content moved, but you want to make sure that people can still find what they’re looking for. This article will show you how to create a Redirect in SharePoint Online.

In classic SharePoint sites, we have the script editor web part, and redirecting can be achieved with JavaScript as in my other article How to Redirect using JavaScript in SharePoint?. Now, We have a modern site collection at “https://crescent.sharepoint.com/sites/sales” and we wanted to redirect that site to another site called sales hub created at “https://crescent.sharepoint.com/sites/saleshub”. So here is how to redirect the home page to another site collection: Create a News link page in SharePoint Online site and then set that page as “Home Page”, so that when users visit a particular site, they’ll be taken to the link provided in the news link. Here are the steps to create a site redirect in SharePoint Online. You can use this method to redirect both subsite and site collections.

  1. Login to your SharePoint Online site, click on the “New” button in the toolbar, and choose “News link”
    sharepoint online redirect home page
  2. Provide the link to redirect. (in my case it’s the URL of the hub site “https://crescent.sharepoint.com/sites/saleshub”), give a title to it, and click on “Post” to create a news link.
    sharepoint online redirect to another site

Step 2: Set the Redirect page as the Home page

Once you have created the redirect page, the next step is to set the redirect page as a home page so that it takes the user to the new site when they visit the site’s home page.

  1. Visit the “Site Pages” library by going to site contents >> Site Pages
  2. Right-click on the redirect page you created and then choose “Set as Home page”.redirect sharepoint online page to different url

From now on, when a user visits the home page, they’ll be redirected immediately to the new site link configured on the redirect page. Visit the “Site Pages” library and edit the “Redirect” page you configured if you want to change the redirect. E.g., In my case, It is: https://crescent.sharepoint.com/sites/Sales/SitePages/

Here is how to create a News link page using PowerShell:

#Connect to PnP Online
Connect-PnPOnline -Url "https://crescent.sharepoint.com/Sites/Purchase" -Interactive

#Create a news link page
$Page = Add-PnPPage -Name "SPDoc.aspx" -LayoutType RepostPage -Title "SharePoint Documentation"
$Page.RepostSourceUrl = "https://learn.microsoft.com/sharepoint"
$Page.Save() 
$Page.Publish()

#Set Home page
Set-PnPHomePage -RootFolderRelativeUrl SitePages/SPDoc.aspx

To stop redirect, append ?stay=true to the URL!

Conclusion

Undoubtedly, redirects are a great way to prevent users from getting lost on your site and improve the user experience. Please note that this method only redirects users to the new site when they visit the home page, not any particular list or library! This method works for classic sites as well (meaning, you can create a News link in classic SharePoint sites and follow the above steps).

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

8 thoughts on “How to Create a Redirect in SharePoint Online?

  • Hi Rajack, do you know if it is possible to do utilizing PnP instead of doing manually?

    Reply
  • this works! but how to edit it when source link get changed again?

    Reply
  • I found a way to set a home page to a news link that redirects to a document library:

    $noClient = "130018"
    Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/$noClient -Interactive
    $page = Add-PnPPage -Name "Accueil" -LayoutType RepostPage
    $f = get-pnpfile -Url "/sites/$noClient/Documents partages/Forms/AllItems.aspx"
    $s = Get-PnPSite
    $w = Get-PnPWeb
    Get-PnPProperty -ClientObject $s -Property Id
    $WebId = $f.Context.Web.Id
    $SiteId = $f.Context.Site.Id
    Get-PnPProperty -ClientObject $f -Property UniqueId
    $ItemId = $f.UniqueId
    
    $page.ThumbnailUrl = "/sites/$noClient/_layouts/15/getpreview.ashx?guidSite=$($SiteId.ToString())&guidWeb=$($WebId.ToString())&guidFile=$($ItemId.ToString())"
    $page.RepostSourceItemId = $ItemId
    $page.RepostSourceSiteId = $SiteId
    $page.RepostSourceWebId = $WebId
    $page.RepostSourceUrl = "https://tenant.sharepoint.com/sites/$noClient/Documents%20partages/Forms/AllItems.aspx"
    $page.Save("Accueil.aspx")
    Set-PnPHomePage -RootFolderRelativeUrl "SitePages/Accueil.aspx"
    
    Reply
  • Hi, It seems that the approach to set a doc lib as a home page does not work anymore (https://www.sharepointdiary.com/2017/02/sharepoint-online-change-home-page-using-powershell.html). I would like to use your news link approach to do so, but I can’t seem to find a way in PowerShell to give the redirection URL. I see how to create a modern page (https://www.sharepointdiary.com/2019/08/create-modern-page-in-sharepoint-online-using-powershell.html), but not how to create a repost and set the redirection value. Thank you!

    Reply
  • Do you have a way to create a site using the Template type REDIRECTSITE#0, mimicking what SP Online does when a URL is changed?

    Reply
  • this is really useful, thank you!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *