Programmatically set the front page per site? I have a site that is using a 'fake' multi-site instance (I think, someone else implemented it). We created 3 directories in sites:


sites/site1
sites/site2
sites/site3


and in each settings.php inside these directories it includes the original settings.php from the default directory.

I am overriding the theme successfully in these files by doing $config['system.theme']['default'] = 'theme2';

When I try doing $config['system.site']['page']['front'] = '/node/239';
it works only on cache flush.

For example if I am on site 1 I see the front page set in the UI.
Then when I switch to site2.example.test I still see the default front page instead of what is on /node/239.
When I flush the cache, the reverse happens; site 2 homepage shows /node/239 and so does site 1.

I have also tried setting this in an event listener:

public function kernel_request(Event $event) {
    $config = \Drupal::configFactory()-&gt;getEditable('system.site');
    $site_path = \Drupal::service('site.path');
    $site_path = explode('/', $site_path);
    $site_name = $site_path[1];

    if ($site_name === 'site2' &amp;&amp; $event-&gt;getRequest()-&gt;getPathInfo() == '/') {
      $config-&gt;set('page.front', '/node/239')-&gt;save();
    }
    else {
      $config-&gt;set('page.front', '/home-content')-&gt;save();

    }
  }


This now does the right thing, but only after loading the page and then refreshing.

Could anyone tell me what the "correct" way of doing this would be that wont be cached?
Thanks to everyone for your responses.
I looked in to using the Domain module but am avoiding for 2 reasons:


It is still in Alpha14 and this is going to be a business critical site
I couldn't work out how to set the domain specific configurations


However, installing the Domain Module and looking at the README file pointed me in the right direction.

For anyone else who is looking to achieve setting a different Front Page per domain:


I used the Drupal Console to generate an Event Subscriber for Kernal.request
In the getSubscribedEvents method you need to set the weight to something greater than 30 which overrides the Page Cache and Dynamic Cache.

$events['kernel.request'] = ['kernel_request', '35'];

I got the editable configuration for the site settings from 

$config = \Drupal::configFactory()-&gt;getEditable('system.site');

and the site name added in sites.php by doing:

$site_path = \Drupal::service('site.path'); 
$site_path = explode('/', $site_path);
$site_name = $site_path[1];

Then added the logic:

if ($site_name === 'site2') {
  $config-&gt;set('page.front', '/node/239')-&gt;save();
}
else {
  $config-&gt;set('page.front', '/main-content')-&gt;save();
}



The Key thing I was missing was setting the Cache Context for sites.
You need to duplicate the default.services.yml from the sites/default directory and rename it to services.yml (if you don't already have this file).

Then you will need to add url.site to the required_cache_contexts array so that is becomes something similar to:

required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions', 'url.site']


Remember to flush the cache and this should work!