<p>Make sure that you change <code>.dev</code>, <code>.com</code>, etc. to reflect your actual environment URLs. They operate based on a partial string match, so as long as your URL contains one of those substrings, it'll pick up the first one it matches.</p>

<p>For example:</p>

<pre><code>'local.mywebsite' =&gt; array(
  'environmentVariables' =&gt; array(
    'userSessionDuration' =&gt; false,
    'devMode' =&gt; true,
    'siteUrl ' =&gt; 'http://local.mywebsite',
  )
),

'mywebsite.com' =&gt; array(
  'environmentVariables' =&gt; array(
    'userSessionDuration' =&gt; false,
    'devMode' =&gt; true,
    'siteUrl ' =&gt; 'http://mywebsite.com',
  )
),
</code></pre>

<hr>

<p><strong>UPDATE</strong></p>

<p>Whoa, I think I may have just realized what the problem is... I copied my example from your original code, and copied a glitch right along with it...</p>

<p>You've listed <code>siteUrl</code> like this:</p>

<pre><code>    'siteUrl ' =&gt; 'http://mywebsite.com'
</code></pre>

<p>Notice anything? There is <em>an extra space</em> between <code>siteUrl</code> and the closing quote.</p>

<pre><code>    'siteUrl '
</code></pre>

<p>... should be:</p>

<pre><code>    'siteUrl'
</code></pre>

CC BY-SA 3.0
2014-09-17T10:20:37.010Z
Thank you Lindsey with the eagle eyes! Words cannot express how much of a n00b I feel right now... That’s got it working. However, the documentation states that the config settings **take precedence over the Site URL setting in Settings → General**, which is not the case. Whatever URL is put there is used, unless you put `{siteUrl}` in the field. I'll let the guys at Craft know about that.
Katrin
CC BY-SA 3.0
2014-09-17T10:45:32.707Z
Oooooh. Easy mistake to make. Those key names could perhaps be trimmed when Craft is going over them, eh?
Fred Carlsen
CC BY-SA 3.0
2014-09-17T02:46:12.827Z
2014-09-17T04:24:22.113Z
2014-09-17T04:24:22.113Z
Lindsey D
<p>As of Craft 2.2, you should now be using the new siteUrl setting. <a href="https://craftcms.stackexchange.com/questions/920/what-s-the-recommended-way-to-set-the-site-url/921#921">See this reply</a> for more details.</p>

<p>Your variable siteUrl from environmentVariables should still work, though.</p>

<p>What do you see if you add this to a test template?</p>

<pre><code>&lt;pre&gt;
  {{ dump(craft.config.get('environmentVariables')) }}
&lt;/pre&gt;
</code></pre>

<p>Check out <a href="http://buildwithcraft.com/help/site-url" rel="nofollow noreferrer">How is the Site URL determined?</a> from the docs as well.</p>

CC BY-SA 3.0
2014-09-16T21:51:23.667Z
I get this: `array(1) { ["siteUrl "]=> string(30) "http://mysite.dev" }`
Katrin
CC BY-SA 3.0
2014-09-16T23:21:11.253Z
The post you link to was answered by Brandon on the 8th July. The first post I link to and followed was answered by Brandon on the 8th September, so technically what I've got should be working right? Hmpf.
Katrin
CC BY-SA 3.0
2014-09-16T23:30:44.970Z
Well, environmentVariables in the Site URL setting works in my installations. What version are you on? You should send a support ticket through the support widget, with database-dump. Perhaps something fishy is going on. Either way, I suggest you go for the siteUrl config option instead, which is the recommended way.
Fred Carlsen
CC BY-SA 3.0
2014-09-17T10:39:15.643Z
Thanks @fred, turns out I was being a n00b and need better glasses ;)
Katrin
CC BY-SA 3.0
2014-09-17T10:41:32.480Z
We all need some strong glasses from time to time ;)
Fred Carlsen
CC BY-SA 3.0
2017-08-18T17:41:56.407Z
Great tip to use `{{ dump(craft.config.get('environmentVariables')) }}`
Alex Kendrick
CC BY-SA 3.0
2014-09-16T21:13:37.937Z
2014-09-16T21:13:37.937Z
2017-04-13T12:51:00.200Z
Fred Carlsen
<p>I followed the advice from <a href="https://craftcms.stackexchange.com/questions/2428/multi-environment-config-for-siteurl-not-working/2433#2433">this</a> and <a href="https://craftcms.stackexchange.com/questions/1771/environment-variable-siteurl-ignored">this</a> post, but I just can't get my environment specific <code>siteUrl</code>s to work.</p>
<p>This is what my config file looks like:</p>
<pre><code>return array(

    '*' =&gt; array(
      'errorTemplatePrefix' =&gt; &quot;pages/&quot;,
    ),

    '.dev' =&gt; array(
      'environmentVariables' =&gt; array(
        'userSessionDuration' =&gt; false,
        'devMode' =&gt; true,
        'siteUrl ' =&gt; 'http://myurl.dev',
      )
    ),

    '.com' =&gt; array(
      'environmentVariables' =&gt; array(
        'userSessionDuration' =&gt; false,
        'devMode' =&gt; true,
        'siteUrl ' =&gt; 'http://myurl.com',
      )
    ),

    '.org' =&gt; array(
      'environmentVariables' =&gt; array(
        'siteUrl'  =&gt; 'http://myurl.org',
      )
    )
);
</code></pre>
<p>These <strong>do not take precedence</strong> over any URL specified in <code>Settings &gt; General</code> in the CP as outlined in the docs. If I set the <code>Site URL</code> field to <code>{siteUrl}</code> in the CP, then my links are broken and look like this: <code>{siteUrl}/link-to-a-page</code>.</p>
<p>Am I missing something else to get the <code>siteUrl</code> settings to work?</p>
<hr />
<h2>Update</h2>
<p>Fixed the additional space in 'siteUrl ', thanks to Lindsey.</p>
<p>My config settings now look like this:</p>
<pre><code>'*' =&gt; array(
  'errorTemplatePrefix' =&gt; &quot;pages/&quot;,
),
// local
'.dev' =&gt; array(
  'devMode' =&gt; true,
  'userSessionDuration' =&gt; false,
  'environmentVariables' =&gt; array(
    'siteUrl' =&gt; 'http://myurl.dev',
  )
),
// staging
'.com' =&gt; array(
  'devMode' =&gt; true,
  'userSessionDuration' =&gt; false,
  'environmentVariables' =&gt; array(
    'siteUrl' =&gt; 'http://myurl.com',
  )
),
// live
'.org' =&gt; array(
  'environmentVariables' =&gt; array(
    'siteUrl'  =&gt; 'http://myurl.org',
  )
)  
</code></pre>
<p>With this and adding <code>{siteUrl}</code> in the CP, everything works as expected - hooray!</p>
<p>It does however not reflect what the Craft docs say, as they state that the config settings &quot;<strong>will take precedence over the Site URL setting in Settings → General</strong>&quot;. I've contacted the Craft team to let them know about this.</p>
<hr />
<h2>Update #2</h2>
<p>Got this response from Brandon:</p>
<blockquote>
<p>“I'm guessing that when you added 'siteUrl' to your config, you put it inside the environmentVariables array? (which would explain why adding {siteUrl} to the CP setting made it work.)</p>
<p>When the documentation is referring to the siteUrl config setting, it's referring to an actual top-level config setting, not some custom &quot;siteUrl&quot; environmentVariable that happens to have the same name.”</p>
</blockquote>
<p>So I've taken the setting out of <code>environmentVariables</code>, and hey presto, it all works as expected. You even get a helpful message in the CP:</p>
<p><img src="https://cl.ly/image/1V120c2m2N0o/Screen%20Shot%202014-09-19%20at%2010.45.00.png" alt="screenshot" /></p>
<p>Final working code:</p>
<pre><code>'*' =&gt; array(
  'errorTemplatePrefix' =&gt; &quot;pages/&quot;,
),
// local
'.dev' =&gt; array(
  'devMode' =&gt; true,
  'userSessionDuration' =&gt; false,
  'siteUrl' =&gt; 'http://myurl.dev',
),
// staging
'.com' =&gt; array(
  'devMode' =&gt; true,
  'userSessionDuration' =&gt; false,
  'siteUrl' =&gt; 'http://myurl.com',
),
// live
'.org' =&gt; array(
  'siteUrl'  =&gt; 'http://myurl.org',
)
</code></pre>
<p>Got there in the end - phew!</p>

<config><siteurl>
Environment specific siteUrl settings not working
# Environment specific siteUrl settings not working

(Asked by: username_0 on 2014-09-16)

I followed the advice from this and this post, but I just can't get my environment specific siteUrls to work.
This is what my config file looks like:
return array(

    '*' => array(
      'errorTemplatePrefix' => "pages/",
    ),

    '.dev' => array(
      'environmentVariables' => array(
        'userSessionDuration' => false,
        'devMode' => true,
        'siteUrl ' => 'http://myurl.dev',
      )
    ),

    '.com' => array(
      'environmentVariables' => array(
        'userSessionDuration' => false,
        'devMode' => true,
        'siteUrl ' => 'http://myurl.com',
      )
    ),

    '.org' => array(
      'environmentVariables' => array(
        'siteUrl'  => 'http://myurl.org',
      )
    )
);

These do not take precedence over any URL specified in Settings > General in the CP as outlined in the docs. If I set the Site URL field to {siteUrl} in the CP, then my links are broken and look like this: {siteUrl}/link-to-a-page.
Am I missing something else to get the siteUrl settings to work?

Update
Fixed the additional space in 'siteUrl ', thanks to Lindsey.
My config settings now look like this:
'*' => array(
  'errorTemplatePrefix' => "pages/",
),
// local
'.dev' => array(
  'devMode' => true,
  'userSessionDuration' => false,
  'environmentVariables' => array(
    'siteUrl' => 'http://myurl.dev',
  )
),
// staging
'.com' => array(
  'devMode' => true,
  'userSessionDuration' => false,
  'environmentVariables' => array(
    'siteUrl' => 'http://myurl.com',
  )
),
// live
'.org' => array(
  'environmentVariables' => array(
    'siteUrl'  => 'http://myurl.org',
  )
)  

With this and adding {siteUrl} in the CP, everything works as expected - hooray!
It does however not reflect what the Craft docs say, as they state that the config settings "will take precedence over the Site URL setting in Settings → General". I've contacted the Craft team to let them know about this.

Update #2
Got this response from Brandon:

“I'm guessing that when you added 'siteUrl' to your config, you put it inside the environmentVariables array? (which would explain why adding {siteUrl} to the CP setting made it work.)
When the documentation is referring to the siteUrl config setting, it's referring to an actual top-level config setting, not some custom "siteUrl" environmentVariable that happens to have the same name.”

So I've taken the setting out of environmentVariables, and hey presto, it all works as expected. You even get a helpful message in the CP:

Final working code:
'*' => array(
  'errorTemplatePrefix' => "pages/",
),
// local
'.dev' => array(
  'devMode' => true,
  'userSessionDuration' => false,
  'siteUrl' => 'http://myurl.dev',
),
// staging
'.com' => array(
  'devMode' => true,
  'userSessionDuration' => false,
  'siteUrl' => 'http://myurl.com',
),
// live
'.org' => array(
  'siteUrl'  => 'http://myurl.org',
)

Got there in the end - phew!

**Tags:** config, siteurl


---

## 2 answers

### Answer by username_1 on 2014-09-17. Score: 3 | Accepted answer

Make sure that you change .dev, .com, etc. to reflect your actual environment URLs. They operate based on a partial string match, so as long as your URL contains one of those substrings, it'll pick up the first one it matches.
For example:
'local.mywebsite' => array(
  'environmentVariables' => array(
    'userSessionDuration' => false,
    'devMode' => true,
    'siteUrl ' => 'http://local.mywebsite',
  )
),

'mywebsite.com' => array(
  'environmentVariables' => array(
    'userSessionDuration' => false,
    'devMode' => true,
    'siteUrl ' => 'http://mywebsite.com',
  )
),


UPDATE
Whoa, I think I may have just realized what the problem is... I copied my example from your original code, and copied a glitch right along with it...
You've listed siteUrl like this:
    'siteUrl ' => 'http://mywebsite.com'

Notice anything? There is an extra space between siteUrl and the closing quote.
    'siteUrl '

... should be:
    'siteUrl'

> **Comments:**
> **username_0**: Thank you Lindsey with the eagle eyes! Words cannot express how much of a n00b I feel right now... That’s got it working. However, the documentation states that the config settings **take precedence over the Site URL setting in Settings → General**, which is not the case. Whatever URL is put there is used, unless you put `{siteUrl}` in the field. I'll let the guys at Craft know about that.  
> **username_2**: Oooooh. Easy mistake to make. Those key names could perhaps be trimmed when Craft is going over them, eh?  

---

### Answer by username_2 on 2014-09-16. Score: 2

As of Craft 2.2, you should now be using the new siteUrl setting. See this reply for more details.
Your variable siteUrl from environmentVariables should still work, though.
What do you see if you add this to a test template?

  {{ dump(craft.config.get('environmentVariables')) }}


Check out How is the Site URL determined? from the docs as well.

> **Comments:**
> **username_0**: I get this: `array(1) { ["siteUrl "]=> string(30) "http://mysite.dev" }`  
> **username_0**: The post you link to was answered by Brandon on the 8th July. The first post I link to and followed was answered by Brandon on the 8th September, so technically what I've got should be working right? Hmpf.  
> **username_2**: Well, environmentVariables in the Site URL setting works in my installations. What version are you on? You should send a support ticket through the support widget, with database-dump. Perhaps something fishy is going on. Either way, I suggest you go for the siteUrl config option instead, which is the recommended way.  
> **username_0**: Thanks @fred, turns out I was being a n00b and need better glasses ;)  
> **username_2**: We all need some strong glasses from time to time ;)  
> **username_3**: Great tip to use `{{ dump(craft.config.get('environmentVariables')) }}`  

---

