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:
- 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.
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).
Hi, Can you think of a reason or scenario when someone would actually want/need to use the virtualfolder?
Sure,
I have a blog post on almost the same topic at http://kverheire.blogspot.be/2014/07/sitecore-hidden-gems-virtual-site-setup.html where I specify this case:
For example, you might want the following structure within Sitecore :
“Corporate Home > Tertiary pages > B2B > Support” to be disclosed under the following url:
http://www.corporate.com/support/
That should help clarify the use of the virtualfolder approach as well
Hello Mark,
What if you need virtual folder name be different depending on the language?
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.