The default magento-vars.php file that is referenced through the Adobe Commerce documentation leaves a lot to be desired and can become a pain when managing stores with many websites and store views. Luckily we can simplify this configuration using the match implementation within PHP8.

This version of the script allows us to configure new store fronts by adding a single case to the match statement.

$host = $_SERVER['HTTP_HOST'] ?? '';
$ephemeralHostScope = fn(string $host): ?string => substr_count($host, '.') === 4 ? strtok($host, '.') : null;

$_SERVER["MAGE_RUN_TYPE"] = 'store';
$_SERVER["MAGE_RUN_CODE"] = match(true) {
    $ephemeralHostScope($host) === 'us' || str_contains($host, '') => 'us',
    $ephemeralHostScope($host) === 'gb' || str_contains($host, '') => 'gb',
    $ephemeralHostScope($host) === 'cn' || str_contains($host, '') => 'cn',
    default => 'base'

We are targeting two URL formats within this upgrade script.

  1. Custom CNAMES records that point to (e.g
  2. Adobe Cloud dynamic urls usually in the format of https://<store>.<integration_env>.<region>