In short, Host-named site collections allows you to have unique URL addresses for each site collection. Say for e.g. Instead of having a typical “Sales” site URL as: http://sharepoint.yourcompany.com/sites/sales, You can have it as http://sales.yourcompany.com and for HR, it can be http://hr.yourcompany.com and so on. As per Technet, HNSC as the preferred method for deploying site collections in SharePoint 2013. So, let’s see how to create host named site collection in SharePoint 2013 using PowerShell.
Before heading into creating Host-named site collections, There are 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, Its possible to create site collections with unique URLs by creating separate web applications in traditionally way, 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. Where as, each host-named site collections have a unique DNS host name and their own top-level URL. Here is how to create 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 http://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 = "http://G1WFE01" New-SPSite -URL $ServerName -Name "HNSC Root" -OwnerAlias "Global\SvcOwner"
This site collection will be used for search crawl. The above two steps can be performed either by PowerShell or with Central Admin UI and they are one-time activity. 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 = "http://WFE01" $OwnerID = "Crescent\Support" $OwnerMail= "[email protected]" $SiteURL = "http://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 Team site template. Hit the URL in browser and you should be able to access the site now!!
DNS for host named site collections: In DNS, either each of the HNSC URL 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 my 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