How to Change Site Collection URL in SharePoint?

How to change SharePoint site URL?

At times, we get requests to change the Site collection URLs. While it’s relatively straightforward and easy by going to Site Actions >> Site Settings >> Title, description, and icon under Look and Feel to change the sub-site’s URL, changing the site collection URL is not so!

how to change the site url in sharepoint

You can Change the URL of SharePoint 2010 Sub-Site using PowerShell also:

Get-SPWeb http://sharepoint.com/sites/sitecollection/subsite | Set-SPWeb -RelativeUrl newsubsiteURL

How to Change Site Collection URL in SharePoint?

To change the site collection’s URL, there is no out-of-the-box user interface or direct ways. So, after making sure the destination URL’s managed path is already in place and verifying the target site collection URL doesn’t exist, I do this three-step manual process.

  1. Backup the Source Site collection
  2. Delete the Source Site collection (Yes, its must! we’ve to delete the site collection before restoring it. Otherwise you will end up in No content databases are available for this operation GUID conflict issue.)
  3. Restore the Backup with the target URL

In MOSS 2007, I used to do it with STSADM as to change site collection URL:

stsadm -o backup -url http://sharepoint.crescent.com/sites/source -overwrite -filename source.bak
stsadm -o deletesite -url http://sharepoint.crescent.com/sites/source
stsadm -o restore -url http://sharepoint.crescent.com/sites/destination -filename source.bak

Now, from SharePoint 2010 onwards, with the help of PowerShell, Why don’t try placing them into a script file to save some time?

Change SharePoint site collection URL using PowerShell:

To rename a site URL in SharePoint, use this PowerShell script:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Get the Source Site Collection URL
$sourceURL = Read-Host “Enter the Source Site Collection URL:”
 
#Get the Target Site Collection URL
$targetURL = Read-Host “Enter the Destination Site Collection URL”
 
#Location for the backup file
$backupPath = Read-Host “Enter the Backup File name & location (E.g. c:\temp\Source.bak):”

Try
{
  #Set the Error Action
  $ErrorActionPreference = "Stop"

 Write-Host "Backing up the Source Site Collection..."-ForegroundColor DarkGreen
 Backup-SPSite $sourceURL -Path $backupPath -force
 Write-Host "Backup Completed!`n"

 #Delete source Site Collection
 Write-Host "Deleting the Source Site Collection..."
 Remove-SPSite -Identity $sourceURL -Confirm:$false
 Write-Host "Source Site Deleted!`n"

 #Restore Site Collection to new URL
 Write-Host "Restoring to Target Site Collection..."
 Restore-SPSite $targetURL -Path $backupPath -Confirm:$false
 Write-Host "Site Restored to Target!`n"

 #Remove backup files
 Remove-Item $backupPath
}
catch
{
 Write-Host "Operation Failed. Find the Error Message below:" -ForegroundColor Red
 Write-Host $_.Exception.Message -ForegroundColor Red
}
finally
{
 #Reset the Error Action to Default
 $ErrorActionPreference = "Continue"
}

write-host "Process Completed!"

I love PowerShell! The above method is also applicable when you want to change the Managed Path of your site collection (both SharePoint 2007 & SharePoint 2010). To change host-named site collection’s URL, you can simply use this PowerShell script:

$site = Get-SPSite -Identity "http://sales.crescent.com/teams/cloud"
$site.rename("http://sales.crescent.com/teams/CloudHosting")

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

13 thoughts on “How to Change Site Collection URL in SharePoint?

  • October 7, 2020 at 10:06 PM

    I’ve run into issues occasionally with your short script to rename a Managed Path URL. It can cause unintentional consequences if you don’t do a config refresh and an recycle the app pool. This is the script I use now, a big part of which is based on your farm iisreset script:

    $OldURL = ‘https://dev.SP.com/sites/test_03’
    $NewURL = ‘https://dev.sp.com/sites/test_04’

    $site = Get-SPSite $OldURL -Verbose
    $uri = New-Object System.Uri($NewURL)
    $site.Rename($URI)
    $site = Get-SPSite $NewURL -Verbose
    ((Get-SPSite $site).contentdatabase).RefreshSitesInConfigurationDatabase()

    $Servers = Get-SPServer | Where-Object {$_.Role -ne “Invalid” }

    foreach ($server in $servers)
    {
    Write-Host “`n`rRestarting IIS on server: $($Server.Name)”
    IISRESET $Server.Address

    Write-Host ” `n`r IIS status for server $($server):”
    IISRESET $server.Address /status
    }
    Write-host “`n`rIIS Restarted on All Servers of the Farm!`n`r” -f Green

    Reply
  • January 9, 2019 at 6:03 AM

    i need for SharePoint Online

    Reply
  • June 6, 2018 at 2:48 PM

    will that work on SP 2013?

    Reply
  • July 24, 2017 at 1:10 PM

    Hi there mates, its wonderful piece of writing about cultureand entirely explained,
    keep it up all the time.

    Reply
  • October 29, 2014 at 4:04 PM

    Great one Thank You vey much

    Reply
  • April 9, 2014 at 4:24 PM

    Great Post. Thank you so much very clear and worked like a charm

    Reply
  • May 8, 2013 at 9:44 AM

    Thanks for the script and posts for extra handling the risk.

    Reply
  • May 2, 2013 at 9:12 AM

    Hi, I see a small risk with this PowerShell script. What happens if the backup fails (at line 13), e.g. due to incorrect path, insufficient disk space etc.? Does the script go on to remove the site collection even if the backup step has failed? Is there a way to end the execution of the script before removing the site collection if the backup would fail?

    Reply
    • May 2, 2013 at 12:20 PM

      True! I’ve updated the code with Try-Catch Block to Mitigate that Risk!! Thanks for your input.

      Reply
  • December 7, 2012 at 3:53 AM

    Nice post, Salaudeen.

    Thanks!

    Reply

Leave a Reply