SharePoint Online: How to Change Subsite URL using PowerShell?

Requirement: Change the URL of a subsite in SharePoint Online.

How to Change the Subsite URL in SharePoint Online?

You may need to change the URL of your subsite for several reasons. Maybe you want to update the name of your subsite to reflect a change in your business, or you just want to simplify the URL for easier sharing. In this blog post, I will show you how to change the URL of a SharePoint Online subsite. Changing the site address of your subsite is a quick and easy process that can be completed in just a few minutes. There are two ways to change the site address, and I will show you two methods. The first method is the easiest, from the web browser interface as an admin, and the second is with PowerShell.

To rename a Subsite URL in SharePoint Online, follow these steps:

  1. Login to your SharePoint Online team site/communication site with site collection admin permissions.
  2. Click on Settings Gear Icon >> Choose “Site Information” and then “View All Site Settings”.
  3. Click on “Title, description, and logo” under the “Look and Feel” group.
  4. Enter the new URL for the subsite and click on “OK”.
    sharepoint online change url of subsite

This renames the subsite address in SharePoint Online. Please note, you’ll see the “Web Site Address” settings only for subsites and not on any top-level site. Alright, How about changing the subsite name in SharePoint Online? Well, set the “Title” field on the above page!

PowerShell to Change Subsite URL in SharePoint Online

Subsites under any modern team sites/classic team sites/or group-connected sites can be changed with PowerShell. Here is the PowerShell to change the URL of a SharePoint Online Subsite:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables
$SiteURL="https://Crescent.sharepoint.com/sites/marketing/us"
$NewSiteURL="/sites/marketing/UnitedStates" #Relative URL of site

Try {
    #Get Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get the Sub-Site
    $Web = $Ctx.web
    $Ctx.Load($web)
    $Ctx.ExecuteQuery()
 
    #change subsite url sharepoint online powershell
    $web.ServerRelativeUrl = $NewSiteURL
    $Web.Update()
    $Ctx.ExecuteQuery()
     
    Write-host "Sub-site URL has been Changed to '$NewSiteURL'" -ForegroundColor Green  
}
Catch {
    write-host -f Red "Error Changing Subsite URL!" $_.Exception.Message
}

Similarly, to change the subsite title, use the below PowerShell command (This can be applied to both top-level or at subsites):

$Web.Title = "New Name for the Site"

PnP PowerShell to Rename a SharePoint Online Subsite

Let’s walk through the steps necessary to change the URL of a subsite in SharePoint Online using a PowerShell script:

#Variables
$SiteURL="https://crescent.sharepoint.com/sites/Retail/us"
$NewName = "United States"
$NewURL="/sites/Retail/UnitedStates" #Server Relative URL of subsite

Try {
    #Connect to the Subsite
    Connect-PnPOnline -Url $SiteURL -Interactive
    
    #Get the subsite
    $Web = Get-PnPWeb
    
    #change subsite name
    $Web.Title = $NewName
    #Change SharePoint site url
    $Web.ServerRelativeUrl = $NewURL
    $Web.Update()
    Invoke-PnPQuery
     
    Write-host "Subsite has been Renamed!" -ForegroundColor Green  
}
Catch {
    write-host -f Red "Error Renaming Subsite!" $_.Exception.Message
}

When you change the site URL in SharePoint, pay special attention to any URLs referenced in documents, bookmarks, navigational elements, JavaScript, CSS, or scripts that may need to be updated with the new site. (It is a best practice to always use relative URLs to avoid these sorts of issues during a URL change, as no automatic redirects are created to the new site URL).

Can you change the URL for a SharePoint Online site?

Sure, To change the site URL of a SharePoint Online site collection, use: SharePoint Admin Center >> Active Sites >> Select the site collection you want to rename >> Click on the “Edit” link, Provide the Site’s new URL, and hit the “Save” button. Or use SharePoint Online Management Shell PowerShell cmdlet ‘Start-SPOSiteRename’ or PnP PowerShell’ Rename-PnPTenantSite’: How to Change the Site URL in SharePoint Online?

How to change the site name in SharePoint Online?

To change the site title of a SharePoint Online site collection, Browse to your SharePoint site where you want to change the name >> Click on Settings gear >> Choose “Site Information” link >> Enter the Site name value and hit Save to change the name to your SharePoint site.
More info: Change site title in SharePoint Online

How to rename a file in SharePoint Online?

The quickest way to rename a document is: Browse to the location where the files are located, Right-click on your desired File and Choose the “Rename” from its context menu (Or Select the File >> Click on the “Rename” button in the Toolbar). Provide a new name to the file in the Rename pop-up and click Save.
More info: Rename a Document in SharePoint Online

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

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