Experimental project

This is a sandbox project, which contains experimental code for developer use only.

Allows different config overrides for the same site using site directories.

Have you ever wanted to present different versions of your site to different audiences? By creating multiple site directories for the same site, you can vary your site configuration based on the domain, subdomain, or URL visited. Site Directory Overrides isolates the global overrides in each setings.php file so that overrides in one site directory do not affect others, allowing you to give each audience a version of your site configured just for them.

Features

  • Isolates config cache by site directory
  • Isolates router cache by site directory
  • Provides a custom cache context for site directory

Post-Installation

To override configuration for a specific site directory, add entries to its settings.php file. For example, to set a different home page for a brand site:

Example: sites/brand-1/settings.php

$config['system.site']['page']['front'] = '/user/login';

This will set the home page to /user/login for the brand-1 site while sites that do not have their own directories will continue to use the front page of the main site, which defaults to /node. You can override any configuration value in this way, and the module will ensure that overrides are isolated to the sites using that site directory.

Important: To ensure that rendered output varies by site, add the site_directory cache context to the required_cache_contexts in your site’s services.yml:

parameters:
  renderer.config:
    required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions', 'site_directory']

Similar projects

This project is a simpler alternative to the Domain module. If you prefer to use Drupal’s admin pages to set domain-specific configuration, or if you need to control access to content by domain, the Domain module is what you need.

AI disclosure

This module was developed with assistance from GitHub Copilot.

Supporting organizations: 
Site Directory Overrides was developed to support branded versions of drupalforge.org.

Project information