<p>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.</p>

<p><a href="https://craftcms.stackexchange.com/questions/4535/proper-order-of-multi-environment-config">Proper order of multi-environment config</a></p>

<p>I'm going to use the solution outlined here
<a href="https://craftcookbook.net/recipes/foolproof-multi-environment-config" rel="nofollow noreferrer">https://craftcookbook.net/recipes/foolproof-multi-environment-config</a></p>

CC BY-SA 3.0
2017-07-03T07:22:09.223Z
2017-07-03T07:22:09.223Z
Matt
<p>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</p>

<pre><code>    &lt;?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
        ***************************/
        '*' =&gt; [
            'environmentVariables' =&gt; [
                'assetUrl'  =&gt; '/',
            ],
            'doAnalytics' =&gt; false,
            'omitScriptNameInUrls' =&gt; 'auto',
            'enableCsrfProtection' =&gt; true,
        'siteRoutesSource' =&gt; 'file',
        ],
        /***************************
        DEVELOPMENT
        ***************************/
        '.dev' =&gt; [
            'devMode' =&gt; true,
            'enableTemplateCaching' =&gt; false,
        ],
        $devUrl_au =&gt; [
            'siteUrl' =&gt; [ 'en_au'  =&gt; 'http://' . $devUrl_au . '/',],
        ],
        $devUrl_nz =&gt; [
            'siteUrl' =&gt; [ 'en_nz'  =&gt; 'http://' . $devUrl_nz . '/', ],
        ],
        $devUrl_us =&gt; [
            'siteUrl' =&gt; [ 'en_us'  =&gt; 'http://' . $devUrl_us . '/', ],
        ],
        /***************************
        STAGING
        ***************************/
        $testUrl_au =&gt; [
            'siteUrl' =&gt; [ 'en_au'  =&gt; 'http://' . $testUrl_au . '/', ],
        ],
        $testUrl_nz =&gt; [
            'siteUrl' =&gt; [ 'en_nz'  =&gt; 'http://' . $testUrl_nz . '/', ],
        ],
        $testUrl_us =&gt; [
            'siteUrl' =&gt; [ 'en_us'  =&gt; 'http://' . $testUrl_us . '/', ],
        ],
        /***************************
        PRODUCTION
        ***************************/
        $liveUrl_au =&gt; [
            'doAnalytics' =&gt; true,
            'siteUrl' =&gt; [ 'en_au'  =&gt; 'http://' . $liveUrl_au . '/', ],
        ],
        $liveUrl_nz =&gt; [
            'doAnalytics' =&gt; true,
            'siteUrl' =&gt; [ 'en_nz'  =&gt; 'http://' . $liveUrl_nz . '/', ],
        ],
        $liveUrl_us =&gt; [
            'doAnalytics' =&gt; true,
            'siteUrl' =&gt; [ 'en_us'  =&gt; 'http://' . $liveUrl_us . '/', ],
        ],
    ];
</code></pre>

<config><multi-environment>
Production siteUrl being used in staging environment
# Production siteUrl being used in staging environment

(Asked by: username_0 on 2017-07-03)

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
     [
            '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 . '/', ],
        ],
    ];

**Tags:** config, multi-environment


---

## 1 answers

### Answer by username_0 on 2017-07-03. Score: 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](https://craftcms.stackexchange.com/questions/4535/proper-order-of-multi-environment-config)

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


---

