<p>Craft looks for partial matches to apply config settings (both <code>general.php</code> and <code>db.php</code> which means you can do things like:</p>

<pre><code>'.dev' =&gt; array(
.. 

'.com' =&gt; array(
..
</code></pre>

<p>Craft applies these settings for each match from the top of the file to the bottom. So in your case because you have the the production domain after your subdomain config it matches and overrides your subdomain settings. </p>

<p>Simply swap your config variables over and it'll work.</p>

<pre><code>return array(
  '*' =&gt; array(
    'omitScriptNameInUrls' =&gt; true,
    'generateTransformsBeforePageLoad' =&gt; true,
    'loginPath' =&gt; 'admin',
  ),
  'localhost' =&gt; array(
    'server' =&gt; 'localhost',
    'devMode' =&gt; true,
    'environmentVariables' =&gt; array(
      'basePath' =&gt; 'C:\wamp\www\craftcms',
      'baseUrl'  =&gt; 'localhost/craftcms/',
    )
  ),
  'safs.msu.edu' =&gt; array(
    'server' =&gt; '35.8.12.67',
    'devMode' =&gt; false,
    'environmentVariables' =&gt; array(
      'basePath' =&gt; '',
      'baseUrl'  =&gt; 'http://safs.msu.edu',
    ),
  ),
  'staging.safs.msu.edu' =&gt; array(
    'server' =&gt; '35.8.12.67',
    'devMode' =&gt; true,
    'environmentVariables' =&gt; array(
      'basePath' =&gt; 'staging',
      'baseUrl'  =&gt; 'http://staging.safs.msu.edu',
    ),
  ),
);
</code></pre>

CC BY-SA 3.0
2016-09-14T15:18:37.863Z
Thanks for the quick response. However, when I do that, the config variables seem not to be recognized at all. DevMode is not turned on for the staging site, and my asset paths contain `{baseUrl}` instead of `http://safs.msu.edu` like they did when they were using the root domain settings.
Katie Fritz
CC BY-SA 3.0
2016-09-14T15:24:42.240Z
Yeah - stupid mistake by me - updated answer with the solution :)
Luke Pearce
CC BY-SA 3.0
2016-09-14T15:26:08.853Z
There we go! I should have tried switching the order - makes sense. Thanks.
Katie Fritz
CC BY-SA 3.0
2016-09-14T15:14:59.053Z
2016-09-14T15:27:09.803Z
2016-09-14T15:27:09.803Z
Luke Pearce
<p>I tend to put the settings for the Production site under the wildcard settings '*' and then overwrite any for dev and staging below that.</p>

CC BY-SA 3.0
2016-09-14T15:23:23.327Z
2016-09-14T15:23:23.327Z
Ant Cooper
<p>My question is similar to <a href="https://craftcms.stackexchange.com/questions/5232/subdomain-database-configuration-picking-up-root-domain-config">Subdomain database configuration picking up root domain config</a>, but I don't have any custom database variables. </p>

<p>I have a staging site and a (forthcoming) production site on the same remote shared hosting server. The staging site is at a <code>staging</code> subdomain and the production site will be at the root. </p>

<p>The staging site seems to be using the config variables from the root domain in <code>general.php</code> and <code>db.php</code>. I had to take the production site out of <code>db.php</code> to get the staging site to work at all, and anywhere I'm using environment variables (like my asset paths), they're coming from the production config instead.</p>

<p>This is my <code>general.php</code>:</p>

<pre><code>return array(
  '*' =&gt; array(
    'omitScriptNameInUrls' =&gt; true,
    'generateTransformsBeforePageLoad' =&gt; true,
    'loginPath' =&gt; 'admin',
  ),
  'localhost' =&gt; array(
    'server' =&gt; 'localhost',
    'devMode' =&gt; true,
    'environmentVariables' =&gt; array(
      'basePath' =&gt; 'C:\wamp\www\craftcms',
      'baseUrl'  =&gt; 'localhost/craftcms/',
    )
  ),
  'staging.safs.msu.edu' =&gt; array(
        'server' =&gt; '35.8.12.67',
    'devMode' =&gt; true,
    'environmentVariables' =&gt; array(
      'basePath' =&gt; 'staging',
      'baseUrl'  =&gt; 'http://staging.safs.msu.edu',
    ),
  ),
  'safs.msu.edu' =&gt; array(
    'server' =&gt; '35.8.12.67',
    'devMode' =&gt; false,
    'environmentVariables' =&gt; array(
      'basePath' =&gt; '',
      'baseUrl'  =&gt; 'http://safs.msu.edu',
    ),
  ),
);
</code></pre>

<p><strong>How do I get my config files to recognize the staging subdomain's settings?</strong></p>

<database><config><multi-environment><subdomain>
Root domain config overriding subdomain config
# Root domain config overriding subdomain config

(Asked by: username_0 on 2016-09-14)

My question is similar to Subdomain database configuration picking up root domain config, but I don't have any custom database variables. 
I have a staging site and a (forthcoming) production site on the same remote shared hosting server. The staging site is at a staging subdomain and the production site will be at the root. 
The staging site seems to be using the config variables from the root domain in general.php and db.php. I had to take the production site out of db.php to get the staging site to work at all, and anywhere I'm using environment variables (like my asset paths), they're coming from the production config instead.
This is my general.php:
return array(
  '*' => array(
    'omitScriptNameInUrls' => true,
    'generateTransformsBeforePageLoad' => true,
    'loginPath' => 'admin',
  ),
  'localhost' => array(
    'server' => 'localhost',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'C:\wamp\www\craftcms',
      'baseUrl'  => 'localhost/craftcms/',
    )
  ),
  'staging.safs.msu.edu' => array(
        'server' => '35.8.12.67',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'staging',
      'baseUrl'  => 'http://staging.safs.msu.edu',
    ),
  ),
  'safs.msu.edu' => array(
    'server' => '35.8.12.67',
    'devMode' => false,
    'environmentVariables' => array(
      'basePath' => '',
      'baseUrl'  => 'http://safs.msu.edu',
    ),
  ),
);

How do I get my config files to recognize the staging subdomain's settings?

**Tags:** database, config, multi-environment, subdomain


---

## 2 answers

### Answer by username_1 on 2016-09-14. Score: 2 | Accepted answer

Craft looks for partial matches to apply config settings (both general.php and db.php which means you can do things like:
'.dev' => array(
.. 

'.com' => array(
..

Craft applies these settings for each match from the top of the file to the bottom. So in your case because you have the the production domain after your subdomain config it matches and overrides your subdomain settings. 
Simply swap your config variables over and it'll work.
return array(
  '*' => array(
    'omitScriptNameInUrls' => true,
    'generateTransformsBeforePageLoad' => true,
    'loginPath' => 'admin',
  ),
  'localhost' => array(
    'server' => 'localhost',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'C:\wamp\www\craftcms',
      'baseUrl'  => 'localhost/craftcms/',
    )
  ),
  'safs.msu.edu' => array(
    'server' => '35.8.12.67',
    'devMode' => false,
    'environmentVariables' => array(
      'basePath' => '',
      'baseUrl'  => 'http://safs.msu.edu',
    ),
  ),
  'staging.safs.msu.edu' => array(
    'server' => '35.8.12.67',
    'devMode' => true,
    'environmentVariables' => array(
      'basePath' => 'staging',
      'baseUrl'  => 'http://staging.safs.msu.edu',
    ),
  ),
);

> **Comments:**
> **username_0**: Thanks for the quick response. However, when I do that, the config variables seem not to be recognized at all. DevMode is not turned on for the staging site, and my asset paths contain `{baseUrl}` instead of `http://safs.msu.edu` like they did when they were using the root domain settings.  
> **username_1**: Yeah - stupid mistake by me - updated answer with the solution :)  
> **username_0**: There we go! I should have tried switching the order - makes sense. Thanks.  

---

### Answer by username_2 on 2016-09-14. Score: 0

I tend to put the settings for the Production site under the wildcard settings '\*' and then overwrite any for dev and staging below that.


---

