Host named site collections in SharePoint 2013

What are HNSC

Traditional site collections that we create in SharePoint are Path based site collections

image

Host named site collections have their own url. 

Example

Microsoft recommends using host named site collection.  It is used in SharePoint online and Office 365.

Benefits of HNSCs

A SharePoint farm can have 20 web applications at max.  If we use path based site collections in order to have unique urls we need to create different web applications with different host names.

For example if we need to create following site collections

1. www.companyA.contoso.com/

2. www.companyB.contoso.com

3. www.portals.com

By using path based site collections we need to create 3 web application with appropriate host names. 

But by using host named site collections we can create one web application and 3 site collections with different urls.

Path based site collection are not scalable as we can create at max 20 web applications, while a sharePoint farm can have at max 250000 site collections using shared content database.

When to use Path Based site collections

1. You want separate application pools.

2. You have requirement of self service site creation feature. - You need to use a custom solution for self-service site creation with host-named site collections.

How to create HNSC

HNSC can be created only through powershell script

  1. Create web application
  2. Create root site collection (required for crawling)
  3. Create host named site collections
  4. Set alternate URLs for host named site collection

Let us have a closer look.

  • Create a web application (either through central admin or through powershell). 

I created through central admin

port – 100

Web app name – SharePoint – 100

  • Now create a root site collection.   When root site collection is crawled, all HNSC s also get crawled although they do not appear in content sources

New-SPSite 'https://<servername>:100' -Name 'Root Portal' -Description 'Root site collection' -OwnerAlias 'contoso\administrator' -language 1033 -Template 'STS#0'

  • Now create HNSC.  Use following powershell to create HNSC

New-SPSite 'https://CompanyA.contoso.com:100' -HostHeaderWebApplication 'https://<servername>:100’ -Name ‘CompanyA portal’ -Description 'Portal for CompanyA' -OwnerAlias 'contoso\administrator' -language 1033 -Template 'BLANKINTERNET#0'

New-SPSite 'https://CompanyB.contoso.com:100' -HostHeaderWebApplication 'https://<servername>:100’ -Name ‘CompanyB portal’ -Description 'Portal for CompanyB' -OwnerAlias 'contoso\administrator' -language 1033 -Template 'BLANKINTERNET#0'

Managed paths with host-named site collections

Managed paths can be used with host-named site collections.  Managed paths for HNSC are different from path based site collections.  Managed paths for HNSC are available to all HNSCs in the farm regardless of the web application.  They are limited to 20 per farm.  While managed paths for path based site collection do not apply to path based site collectioins in other web applications. 

To create managed path for HNSC we need to use powershell

New-SPManagedPath ‘dept’ –HostHeader

Now we can create HNSC with managed path

New-SPSite ‘https://CompanyA.contoso.com:100/dept/Technology’ –HostHeaderWbApplication ‘https://<servername>:100’ –Name ‘Technology’ –Description ‘Technology department’ –OwnerAlias ‘contoso\administrator’ –language 1033 –Template ‘BLANKINTERNET#0’

Managed path for path based site collection can be defined at central admin or using powershell

New-SPManagedPath [-RelativeURL] "</RelativeURL>" -WebApplication <WebApplication> creates managed path for a particular web application that can be used by path based site collections of that particular web application

Having done this you can check by browsing the site

Note : – In case you see a 404 error and if you are browsing the site on same local SharePoint server, you would need to change the host file to include then entry

for example to browse https://companyA.contoso.com:100 the entry in host file would be

127.0.0.1 companyA.contoso.com

Further you need to disable LoopBack in registry. To do this manually open registry using regedit and nav to HKEY_LM\System\CCS\Control\LSA

Create dword key with name ‘DisableLoopbackCheck’. Change the value to 1 for this.

It can also be done using powershell

New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword