2

I'm using the following multi-env config. My dev config works as expected. However, when I visit my staging site, it is setting the siteUrl to the production Url

    <?php

    // Dev URL
    $devUrl_au  = "au-site.dev";
    $devUrl_nz  = "nz-site.dev";
    $devUrl_us  = "us-site.dev";

    // Testing URL
    $testUrl_au = "test.site.com.au";
    $testUrl_nz = "test.site.nz";
    $testUrl_us = "test.site.co";

    // Production URL
    $liveUrl_au  = "site.com.au";
    $liveUrl_nz  = "site.nz";
    $liveUrl_us = "site.co";

    return [
        /***************************
        GLOBAL CONFIGURATION
        ***************************/
        '*' => [
            'environmentVariables' => [
                'assetUrl'  => '/',
            ],
            'doAnalytics' => false,
            'omitScriptNameInUrls' => 'auto',
            'enableCsrfProtection' => true,
        'siteRoutesSource' => 'file',
        ],
        /***************************
        DEVELOPMENT
        ***************************/
        '.dev' => [
            'devMode' => true,
            'enableTemplateCaching' => false,
        ],
        $devUrl_au => [
            'siteUrl' => [ 'en_au'  => 'http://' . $devUrl_au . '/',],
        ],
        $devUrl_nz => [
            'siteUrl' => [ 'en_nz'  => 'http://' . $devUrl_nz . '/', ],
        ],
        $devUrl_us => [
            'siteUrl' => [ 'en_us'  => 'http://' . $devUrl_us . '/', ],
        ],
        /***************************
        STAGING
        ***************************/
        $testUrl_au => [
            'siteUrl' => [ 'en_au'  => 'http://' . $testUrl_au . '/', ],
        ],
        $testUrl_nz => [
            'siteUrl' => [ 'en_nz'  => 'http://' . $testUrl_nz . '/', ],
        ],
        $testUrl_us => [
            'siteUrl' => [ 'en_us'  => 'http://' . $testUrl_us . '/', ],
        ],
        /***************************
        PRODUCTION
        ***************************/
        $liveUrl_au => [
            'doAnalytics' => true,
            'siteUrl' => [ 'en_au'  => 'http://' . $liveUrl_au . '/', ],
        ],
        $liveUrl_nz => [
            'doAnalytics' => true,
            'siteUrl' => [ 'en_nz'  => 'http://' . $liveUrl_nz . '/', ],
        ],
        $liveUrl_us => [
            'doAnalytics' => true,
            'siteUrl' => [ 'en_us'  => 'http://' . $liveUrl_us . '/', ],
        ],
    ];
2

I found an existing solution to this. It turns out the order of the file matters and due to the "partial-match", my siteUrl was being set to the staging url and then overriden with the production url.

Proper order of multi-environment config

I'm going to use the solution outlined here https://craftcookbook.net/recipes/foolproof-multi-environment-config

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.