Remove a SharePoint Online site redirect

Context

Last week, I had a problem with a line of business application which uses a SharePoint Online site as backend, this application initialize the backend automatically (site, content types and lists creation) when it’s not already created. In this environment which was not mine, it was requested to start from zero but with the same site name and address so I decided to simply rename the SharePoint Online site through the SharePoint Admin Center to keep this actual site as archive. But I missed an important technical thing, when a site URL is changed, moved to another geo or swapped, a redirect is automatically created with a specific site template to ensure that the old URL is still responding.

This application is checking the HTTP response code of a specific site URL like 200 (OK) or 404 (Not Found) before doing anything. This is why the application was still considerating that the backend site was already created, the old site URL was still responding correctly through the site redirect automatically created after my rename operation! Now it’s time to see how to remove a specific site redirect…

Remove a site redirect

In this article, I’m using the SharePoint Online Management Shell to do all the actions.

Before using any command, you need to connect to the SharePoint Admin Center using the following cmdlet:

Connect-SPOService -Url https://<TENANT-NAME>-admin.sharepoint.com

First, to list all active site redirects on your tenant, you can execute the following cmdlet:

Get-SPOSite -Template REDIRECTSITE#0

Note: REDIRECTSITE#0 is the specific template type used for the site redirects creation in the tenant.

Then you can use the following cmdlet to delete the site redirect permanently:

Remove-SPOSite -Identity https://<TENANT-NAME>.sharepoint.com/sites/<OLD-SITE-NAME>

After this operation, the application initialized a fresh backend as expected without any conflict or error.

Happy coding everyone!

Resources

https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online

https://docs.microsoft.com/en-us/sharepoint/manage-site-redirects

6 thoughts on “Remove a SharePoint Online site redirect

  1. Hello.
    I am logged in as global administrator and i receive this error:

    Remove-SPOSite : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    At line:1 char:1
    + Remove-SPOSite -Identity https://companyxx.sharepoint.com/sites/portal_in
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Remove-SPOSite], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerUnauthorizedAccessException,Microsoft.Online.SharePoint.PowerShell.RemoveSite

    Any suggestions please ?

    Thanks

    Like

  2. I am getting the same error message. Site with the redirect Url is deleted and I can’t add myself to the site collection administrators.. any ideas?

    Cheers!

    Like

    1. You need to be site collection administrator to execute the command, maybe you can request your organization’s SharePoint admin to add you as site collection administrator?

      Like

Leave a comment