This is probably one of the most common questions I've been asked over the years. Unfortunately, Microsoft doesn't provide a UI method for users to change the URL of their site. Given the database schema and the relationships between objects and the URL, I've always been perplexed as to why this was never done. To me it seemed like a pretty easy SQL update.
Although there are many methods to overcome this problem, such as the site backup/restore method described by Todd Klindt, these methods become increasingly more time consuming as the site size grows. The easiest method in my mind still remains using the SPSite.Rename() method. Unfortunately, the MSDN article states at the top that it "Changes the URL of a host-header-named site collection to a new URL.". I believe this is why this method has remained obscure and under-leveraged. At the end of the article, it also states "After the site rename, an app pool recycle is recommended to force refreshing the cache." which is incorrect. An app pool recycle is required in order for the new URL to work correctly.
But enough picking apart MSDN articles... let's get to the good stuff. :-)
The following Powershell script does what we want:
The core of the script is lines 9 and 10.
Remember to recycle your web app's app pool!
Enjoy!
C
The SharePoint Knowledge Collection of Cornelius J. van Dyk, an 9 x SharePoint MVP
Subscribe to:
Post Comments (Atom)
SharePoint Remote Event Receivers are DEAD!!!
Well, the time has finally come. It was evident when Microsoft started pushing everyone to WebHooks, but this FAQ and related announcement...
-
Ever wondered what the new SharePoint Online URLs are all about? Take for example https://cjvandyk.sharepoint.us/:x:/r/sites/Site1... What ...
-
When using NuGet, we can easily run into assembly reference issues. A notorious error message is: CS0012: The type ‘System.Object’ is def...
-
Have you ever started creating a list view in SharePoint and because you're experimenting, you chose to make it a "Private" vi...
No comments:
Post a Comment
Comments are moderated only for the purpose of keeping pesky spammers at bay.