In SharePoint 2013, host-named site collections (HNSC) are all the rage. SharePoint Online has been using them heavily for some time now and in general, they are the preferred method for creating site collections now with SharePoint 2013. If you aren’t familiar with what I mean by host-named site collections, let me give you an example. Host-named site collections give you the ability to provide completely different URLs for a site collection regardless of the web application URL hosting it. For example, you might have a web application URL named http://sharepoint.mycompany.com and under it you have a collaboration site with a URL of http://collaborate.mycompany.com and an Intranet site named http://intranet.mycompany.com. This allows you to host multiple types of SharePoint sites together on a single web application which ultimately reduces the amount of resources your server farm needs for application pools.
Host-named site collections are great, but what if we want to append a path-based site collection onto our HNSC? The TechNet article does a good job explaining HNSC but when I read it, it wasn’t clear to me if you could combine the two. Now, this is interesting but what if your HR department wants their own site collection under http://collaborate.mycompany.com? You could always give them an HNSC as well such as http://hr.mycompany.com. However, if you don’t want that and you really want the URL to be located under your other URL such as http://collaborate.mycompany.com/hr, this can be done with some simple PowerShell commands. If you have worked with HNSC before, you know PowerShell is our only option if we want to use them as there is not any place in Central Administration to set them up.
Just like any site collection, you have to create a managed path for the URL you want. We do this using New-SPManagedPath. We can add explicit or wildcard inclusions just like you can for path-based site collections. Wildcard is the default, if you want explicit, include the –explicit parameter. We also need to add the –HostHeader parameter to indicate this is used with host-named site collections. Here’s an example, where I created the HR explicit path from our example above.
New-SPManagedPath "MyPath" -HostHeader -Explicit
This technically makes this managed path available on any host-named site collection. If you want to see what managed paths have been created for host-named site collections, use Get-SPManagedPath with the –HostHeader command.
Now, we need to create the site collection using New-SPSite. It takes a few parameters but the important ones for this scenario is the URL we want for the new site collection and then –HostHeaderWebApplication to specify which web application hosts the new site collection.
New-SPSite http://wingtip.com/mypath -HostHeaderWebApplication http://webapplicationurl -Name "Site Name" -OwnerAlias domain\user -Template STS#0
When the command is done, you will have a new site collection at the URL you specified. Give it a try for yourself.