Determining website context

Current version: 10.4

You configure additional managed websites for different purposes and different domains by adding them to the site definition node in the Sitecore.config file. For example, you can define a new site to be your published public-facing site or to be used by content editors to access the content management system.

Sitecore determines the website context based on the incoming URL and the following two attributes:

  • hostName – specifies the name of the website as it appears in the incoming URL. It can contain wildcards.

  • virtualFolder – the physical path to the website root folder.

When Sitecore receives an incoming URL, it first compares the URL to the hostName attribute of each site in the <sites> list in the config file.

If the hostName attribute matches the incoming URL or the hostName attribute is empty, Sitecore next compares the virtualFolder attribute.

Sitecore uses the first site definition in the <sites> list where the hostName and virtualFolder attributes match the incoming URL as the context site.

Note

Sitecore checks for sites in the same order that they occur in the list. Therefore, you must list sites starting with the most specific entry and ending with the most general entry. For example, if you have a website where hostName is mysite.com.au and another website where hostName is mysite.com, the entry for mysite.com.au must be first in the list. Otherwise, an incoming URL for mysite.com.au will match the entry for mysite.com first.

Note

Sitecore determines the website context differently for the Experience Editor. Sites are only resolved under the startItem item that is defined in the configuration of a site, If you have multiple sites and an item is not under any startItem item, Sitecore resolves a site for the item as Preview.DefaultSite.

You can change this logic by customizing the Sitecore.Shell.Applications.WebEdit.Commands.OpenExperienceEditor from the Sitecore.ExperienceEditor assembly. This class is used by the webedit:openexperienceeditor command.

Do you have some feedback for us?

If you have suggestions for improving this article,