Change site collection URL in SharePoint 2013

Summary: This post describes the different ways to change the site collection URL in SharePoint 2013.

So, your manager/the business asks you to create a few site collections for some departments in your organization. You quickly spin up some site collections for them to use. After a few weeks, the business decides (of course) SharePoint is great, but the URL’s we chose weren’t all that great. Can you please change them?

There are alot of blog posts out there that describe the different possibilities in this scenario:
– Using backup and restore.
– A great article by Todd Klindt that tells you how to use the Copy-SPSite cmdlet to achieve the same goal but easier!

There is another (easier) way in some scenario’s in which you can change the site collection URL by just using 2 lines of PowerShell with only a second of waiting time!

The solution
Let’s get down to it.. I created this very nice Marketing site collection, using the url: http://sharepoint/sites/marketing. Now I would like to change this to http://sharepoint/sites/sales. Just use the following 2 lines of PowerShell code and you are done!

That is all.. try it out and see that your new URL is working, and the old URL is not working anymore!*NOTE* Thanks to Jaymeson in the comments for pointing out an IISRESET is needed as well!

A little catch
There is a little catch to this. You can only use this to rename site collection URL’s that
– Use “Wildcard inclusion” Managed Paths.
– Are Host named site collections (In which case you could also use Set-SPSiteURL)

You can’t use it to change http://sharepoint/sites/marketing to http://sharepoint/marketing (Even if the Explicit inclusion managed path exists).

Nico – So, is there no way to change “http://sharepoint/sites/marketing to http://sharepoint/marketing (Even if the Explicit inclusion managed path exists)?” I just spun up a site with /sites/ and wildcard inclusion managed paths then realized that I wanted to ensure Global Navigation would work. The best way to do this seems to be reusing terms in site collection navigation which requires… Explicit Inclusion managed paths.

I don’t think that scenario is supported by the rename function. However, you can still create a backup of the site collection and restore it to the location of your choice. Or you could use the Copy-SPSite cmdlet.

Warning! I tried this with a special character in the URL “ü” and this made my site unreachable. Even worse I can’t find the site with powershell as well! In the Admin Control Center I see the site collection but it looks messed up no information is displayed. I know the site is still on the database since the Sitecount on the DB is higher than the amounts of sites I get with the command get-spsite. Any advice how I can change the URL back?

Exception calling “Rename” with “1” argument(s): “Only host part for a host
header site collection or the last segment after a wildcard managed path of a
site collection Url can be renamed. http://WebApp_URL/sites/sales is
an invalid new Url for the site collection at http://WebApp_URL.”
At line:1 char:1
+ $site.Rename(“http://WebApp_URL/sites/sales”)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException

I am using Host named Site Collections with the Wildcard Managed Path of “Sites”. Do this also change the path for the existing subsites as well? In addition, would this chnage the path on the Term Store being used for Managed Navigation or just create a new one? Many thanks in advance/

Yes you should be able to run it. Make sure to do an IISRESET afterwards.
– Subsite URL’s will be changed as well (they are all saved in the database as relative paths)
– For the term store question, I am pretty sure this will keep working. I haven’t tested this though.