Sitecore Managed Sites as Virtual Folders

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:

sites1

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.

sites2

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:

  • Hostname
  • 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.

sites3

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:

sites4

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).

 

Mark Ursino

Mark is Sr. Director at Rightpoint and a Sitecore MVP.

 

4 thoughts on “Sitecore Managed Sites as Virtual Folders

  1. I have setup two sites

    I have configured “customsite” with virtual folder settings and can access the same with http://localdomain/healthcare/.
    however i am facing an issue in a link generated using Url.Action(“Index”,”Home”), it is generating “/api/sitecore/Home/Index” url. upon clicking this url it is not resolving to current site i.e. Context site is “website” not “customsite”.
    to resolve this i tried below approach.
    1) Create a custom processor to add route “healthcare/api/sitecore/{controller}/{action}” with name “healthroute”
    2) use Url.RouteUrl(“healthroute”,new{controller=”home”,action=”index”}).

    above changes are working fine. is there any other/better approach to resolve this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.