I followed the advice from this and this post, but I just can't get my environment specific siteUrl
s 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!