Multi-site Configuration

Multi-site Configuration

The combination of the baseUrlForSite and siteForUrl callbacks configures a site mapping for multi-site support. By configuring a site mapping, you enable Scrivito to differentiate between multiple sites by their individual site IDs and URLs. Scrivito uses this mapping to determine the site the browser is currently displaying, for example. It is also used for cross-site-navigation, i.e., to generate the proper URLs for links on the current site pointing to a page on a different site.

The baseUrlForSite function receives a site ID and should return the base URL of this site if it exists.

The “base URL” is the URL where a specific Scrivito website starts. Depending on your deployment structure, it may or may not include a path. Examples:

The siteForUrl function receives a URL and should return an object containing the site ID under the property siteId and the base URL of the site to which the URL belongs under the property baseUrl:

Scrivito always calls your siteForUrl function with an absolute URL, i.e. including host, protocol etc. Similarly, your baseUrlForSite callback is expected to always return an absolute URL as well.

If siteForUrl is called for a URL that doesn’t belong to any of the sites hosted by your Scrivito instance, your function must return undefined to indicate to Scrivito that this is an external URL.

In the example above, the callback returns a valid site ID for "mysite.net/de" and "mysite.net/en", but if invoked with "mysite.net/some_dummy_value" it would probably return undefined to signal to Scrivito that this URL does not denote a valid site. Scrivito treats this as “site not found”, meaning that it is not responsible for rendering this URL, i.e., both Scrivito.currentPage and Scrivito.currentSiteId will return null, and neither Scrivito.CurrentPage nor Scrivito.NotFoundErrorPage will render anything.

Here is a simple example in which Scrivito recognizes only two sites:

Note that sites and URLs can also be mapped dynamically, i.e., without having to change the configuration.

Providing the mapping is optional. If no mapping is given, Scrivito assumes that your CMS is not multi-site, i.e., handles just one site. If the mapping is present, however, both functions must be provided (defining just one function is considered an error).

Also, an application cannot be configured for multi-site with origin or routingBasePath being specified as well because these option combinations are mutually exclusive.