In short, Host-named site collections allows you to have unique URL addresses for each site collection. E.g., Instead of having a typical “Sales” site URL as: https://sharepoint.yourcompany.com/sites/sales, You can have it as https://sales.yourcompany.com, and for HR, it can be https://hr.yourcompany.com and so on. As per Technet, HNSC is the preferred method for deploying site collections in SharePoint 2013. So, let’s see how to create a host-named site collection in SharePoint 2013 using PowerShell.
Before heading into creating Host-named site collections, There are a few points to ponder:
- All necessary DNS entries must be created prior to creating HNSC (Which is obvious!) You can create a Foward lookup zone in DNS with wildcard entry pointing to the load balancer or Web Server’s IP.
- The web application that houses host-named site collection will be created without any host headers and listening to the default port 80. So the “Default website” of IIS must be deleted first! Also, make sure no other web app is using that port without host headers. If this can’t be done for any reason, You have to manually add the host header entries in the bindings in IIS on every WFE.
Although, It’s possible to create site collections with unique URLs by creating separate web applications traditionally, remember there is a limit of 20 web applications per SharePoint farm!
Create Host-Named Site Collections Step-by-Step:
From the Domain Name System(DNS) perspective, path-based site collections share a common host name in a web application. In contrast, each host-named site collections have a unique DNS host name and their own top-level URL. Here is how to create a host-named site collection in SharePoint 2013.
Step 1: Create hosting Web Application for Host Named site collections
By default, the New-SPWebApplication cmdlet creates web applications in windows classic mode authentication! Make sure you are providing -AuthenticationProvider switch to make it on claims authentication mode.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Set variables for New web application creation $WebAppName = "HNSC Host Web Application" #Variables for new Application Pool $AppPoolName = "HNSC App Pool" #Get the existing Managed Account $AppPoolAccount = Get-SPManagedAccount "Crescent\SvcAppPool" #To utilize existing AppPool, Use: Get-SPServiceApplicationPool <AppPoolName> $ContentDatabase = "SP13_HNSC_Content" $AuthProvider = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication #Create the web application $WebApp = New-SPWebApplication -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount -Name $WebAppName -Port 82 -AuthenticationProvider $AuthProvider -DatabaseName $ContentDatabase -path "C:\inetpub\wwwroot\wss\VirtualDirectories\HNSCHost" #-URL https://G1WFE01
Step 2: Create Blank Root Site collection without templates
The root site collection should be created without assigning any template to it. So, it will be an empty-blank site.
$ServerName = "https://G1WFE01" New-SPSite -URL $ServerName -Name "HNSC Root" -OwnerAlias "Global\SvcOwner"
This site collection will be used for search crawl. The above steps can be performed either by PowerShell or with Central Admin UI, and they are one-time activities. Once we have the host web application and blank root site collection ready, we can create any number of Host header site collections in it.
Step 3. Create host named site collection in SharePoint 2013 using PowerShell
SharePoint 2013 host-named site collections can be created using PowerShell only. Here is the PowerShell script to create a Host-named site collection. The -HostHeaderWebApplication switch identifies the web application where the site collection is to be created.
$HostURL = "https://WFE01" $OwnerID = "Crescent\Support" $OwnerMail= "[email protected]" $SiteURL = "https://sales.crescent.com" $TemplateVal ="sts#0" #Team Site #Create the HNSC New-SPSite -url $SiteURL -HostHeaderWebApplication $HostURL -owneralias $OwnerID -owneremail $OwnerMail -Template $TemplateVal
That’s all! We are done! The above script creates a host-named site collection of the Team site template. Hit the URL in the browser, and you should be able to access the site now!
DNS for a host-named site collection: In DNS, either each of the HNSC URLs should be configured as an A record pointing to the load balancer IP or web server IP. Or created as a wildcard DNS entry (*.Domain.com. E.g., sales.crescent.com; marketing.crescent.com, etc.) so that anything ends with the particular domain name reaches the specific SharePoint farm.
Host-named site collections concepts are explained in another article: Host Named Site Collections in SharePoint.
Technet article for SharePoint 2013 host-named site collections with SSL, Migrating path-based site collections to Host-named site collection, etc.: SharePoint 2013 Host-named site collection architecture and deployment