Sitecore’s native ability to manage multiple web properties is a highly-leveraged feature of the CMS. It supports this via different tree nodes and specific configuration to delineate among sites. This blog post covers several important considerations when managing sites with virtual folders.
Managing Multiple Sites in General
Sitecore supports multiple logical sites by having separate root paths in the content tree:
In addition to this, XML configuration in the
<sites> section (preferably via the
SiteDefinition.config patch) defines what sites map various host names to root content paths. Sites also define a context language, database, etc.
How Sitecore Resolves a Site
Sitecore resolves the correct site via a pipeline process in the
httpRequestBegin pipeline. The SiteResolver sets the context site based on the following criteria:
- Virtual path
- Port number
Sitecore processes the XML in sequence to find the first site that matches the above criteria. Since each site has a
hostName attribute defined, Sitecore first matches against this. Next comes the
virtualFolder which by default is simply “/” but may be changed.
How to Configure a Sitecore Site with a Virtual Folder
To configure a site as a virtual folder, define the
virtualFolder path AND
physicalFolder path to match the expected path.
If you do no define the
physicalFolder in addition to the
virtualFolder Sitecore may either not resolve the site correctly or may throw a YSOD saying a path is null:
Note: if you have configured the Link Provider to use the Display Name for URLs, these virtual and physical paths must actually match the display name, not the item name.
Additionally, you must define virtual folder sites above any non-virtual folder sites that share the same
hostName. This is because Sitecore resolves the sites in sequence based on the configuration so you need more specific combinations of criteria first (e.g. host and path).