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!