Sitecore 9: Rule based configuration

Do you remember how Sitecore configuration files for multiple environments and server configurations were handled? Times, when files needed to be removed during deployment process,  renamed, overwritten or transformed? These times are definitively out!

Starting by Sitecore 9, we have much more comfortable way how to deal with that. We can extend patch files by additional rules which controls how configuration changes are applied. And it is  really simple!

How to create (setup) rule

Rules are configured in web.config file in root of sitecore webfoot. To create a rule just put line like following into <appSettings> section of web.config

By this example, rule “environment” is set to value “UAT”.

Additionally, there is possible to define multiple values for rule. In that case, use comma as delimiter:

How to use rule

Usage of rule is pretty straightforward and easy. The only prerequisite is namespace registration at the root element of configuration patch file:

Complete header in configuration file intended to consume “environment” rule will look like following:

When namespace is defined, you just need use attribute require with appropriate namespace in setting definition.

Advanced usage

There is possible to use certain operators for evaluate rule value. Available operations are and, or and ! (not operator).

Require attribute, when using advanced operators, can look like following:

This example means that section will be processed if environment rule will contain UAT or Testing values, but will be ignored if any of values will be Production.

Sitecore provides two predefined “rules” out of the box.

There are two rules available by Sitecore out of the box:

  • Search rule – used as source for selection of proper configuration files for search index configuration (Lucene, Azure or Solr)
  • Role rule – used as source for applying proper configurations related to server roles – like Standalone, ContentDelivery, ContentManagement, Processing, Reporting or DedicatedDisptach.


Leave a Reply

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