Answers.Body: <p>Make sure to change the "Site URL" setting to <code>{siteUrl}</code> in your control panel settings...</p>
  
  <blockquote>
    <p>Control Panel > Settings > General > "Site URL"</p>
  </blockquote>
  
  <p>Within your config file, you'll also want to put your <code>siteUrl</code> value inside of an <a href="http://buildwithcraft.com/docs/multi-environment-configs#environment-specific-variables">Environment-Specific Variables</a> sub-array:</p>
  
  <pre><code>'mynewcraftsite.dev' =&gt; array(
      'devMode' =&gt; true,
      'environmentVariables' =&gt; array(
          'siteUrl' =&gt; 'http://www.mynewcraftsite.dev/'
      )
  ),
  'mynewcraftsite.com.au' =&gt; array(
      'environmentVariables' =&gt; array(
          'siteUrl' =&gt; 'http://www.mynewcraftsite.com.au/'
      )
  )
  </code></pre>
  
  <hr>
  
  <p>Here's how Craft is compiling all of that... </p>
  
  <p>Within each of your environment configurations, there are many <a href="http://buildwithcraft.com/docs/config-settings">config settings</a> that you can apply to that specific environment. Additionally, each environment can have a sub-array called <code>environmentVariables</code>, which allows you to set whatever unique variables you want. The most common examples are <code>siteUrl</code> and <code>fileSystemPath</code> (great for setting up assets sources), but you can truly set whatever environment variables you want.</p>
  
  <p>Once you've set the <code>siteUrl</code> value in your environment variables array, you now need to use that value... This is where the control panel settings page comes into play. Changing "Site URL" to simply <code>{siteUrl}</code> tells Craft to pull that value from your environment variables.</p>
  
  <p><strong>IMPORTANT:</strong> Notice the single set of curly braces, and the lack of spacing between the variable name and the braces. This is the syntax difference between <strong>environment variables</strong> and <strong>Twig variables</strong>.</p>
  
  <p>That's it! When you create a path, Craft will use whatever is in the "Site URL" setting. And since that's pulling in your environment variable, that's what you'll get.</p>
  
  <hr>
  
  <p>Lastly, allow me to point out a few things in your example which may also be stopping this from working for you (feel free to update the example in your question to fix these issues)...</p>
  
  <p><strong>Most importantly:</strong> You're combining data that should be stored in two separate files... <code>craft/config/db.php</code> and <code>craft/config/general.php</code>. While the multi-environment format is the same, you'll need to separate the data shown in your example. Put most of your settings into <code>general.php</code>, only the following belong in <code>db.php</code>:</p>
  
  <ul>
  <li><code>server</code></li>
  <li><code>user</code></li>
  <li><code>password</code></li>
  <li><code>database</code></li>
  <li><code>tablePrefix</code></li>
  </ul>
  
  <p>You also have an errant line of code in your example... This line should definitely be removed:</p>
  
  <pre><code>'localhost' or '127.0.0.1'.
  </code></pre>
  
  <p>Finally, you've left some crucial security information in your example... All of your database connection info is exposed (as well as your true domain names in your <code>siteUrl</code> examples).</p>
  
  <hr>
  
  <p>Hope that helps... If you fix the bugs in your example code, I'll remove my corresponding notes from this answer. :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-25T05:27:34.540Z
Answers.LastActivityDate: 2014-06-25T05:56:55.333Z
Answers.LastEditDate: 2014-06-25T05:56:55.333Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <p>The siteUrl value you are trying to set should not be set in the <code>db.php</code> file.  It needs to be set in the <code>general.php</code> file.  It also seems like you have a few other variables that should be moved over to <code>general.php</code> too.</p>
  
  <p>You have one line that needs to be removed completely or commented out.  <code>'localhost' or '127.0.0.1'.</code> is not correct.</p>
  
  <p><strong>general.php</strong></p>
  
  <pre><code>return array(
      //All environments
      '*' =&gt; array(
          'omitScriptNameInUrls' =&gt; true,
      )
  
      //Testing environment
      'www.mynewcraftsite.dev' =&gt; array(
          'environmentVariables' =&gt; array(
              'siteUrl' =&gt; 'http://www.mynewcraftsite.dev'
          )
      ),
  
      //Live environment
      'www.mynewcraftsite.com.au' =&gt; array(
          'environmentVariables' =&gt; array(
              'siteUrl' =&gt; 'http://www.mynewcraftsite.com.au'
          )
      )
  );
  </code></pre>
  
  <p><strong>db.php</strong></p>
  
  <pre><code>return array(
  
      //All environments
      '*' =&gt; array(
          'tablePrefix' =&gt; 'craft'
      ),
  
      //Testing environment
      'www.mynewcraftsite.dev' =&gt; array(
          'server' =&gt; 'localhost',
          'user' =&gt; 'testuser',
          'password' =&gt; 'testpassword',
          'database' =&gt; 'testdatabase'
      ),
  
      //Live environment
      'www.mynewcraftsite.com.au' =&gt; array(
          'server' =&gt; 'localhost',
          'user' =&gt; 'liveuser',
          'password' =&gt; 'livepassword',
          'database' =&gt; 'livedatabase'
      )
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-25T05:56:32.323Z
Answers.LastActivityDate: 2014-06-25T05:56:32.323Z
Answers.UserDisplayName: Ben Parizek
Answers.Body: <p>You might find this helpful: <a href="https://nystudio107.com/blog/multi-environment-config-for-craft-cms" rel="nofollow noreferrer">Multi-Environment Config for Craft CMS</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-04T17:24:53.107Z
Answers.LastActivityDate: 2016-12-04T17:24:53.107Z
Answers.UserDisplayName: andrew.welch
Body: <p>I'm building www.mynewcraftsite.com.au, but I also wanna create www.mynewcraftsite.dev which is a testing server to preview to my clients. I've heard that I can set this up with Craft without going through the drudgery of downloading/uploading databases and updating urls in the db, users ... etc.</p>
  
  <p>I've been reading the Craft CMS documentation for "Multi-Environment Configs".  So far I've got this in my db.php file;</p>
  
  <pre><code>return array(
      //All environments
      '*' =&gt; array(
          'omitScriptNameInUrls' =&gt; true,
          'localhost' or '127.0.0.1'.
          'server' =&gt; 'localhost',
          'user' =&gt; 'dashing-print',
          'password' =&gt; 'f#$njEwFRn3&amp;2',
          'database' =&gt; 'dashing-print',
          'tablePrefix' =&gt; 'craft'
      ),
  
      //Testing environment
      'www.mynewcraftsite.dev' =&gt; array(
          'siteUrl' =&gt; 'www.dashingprint.dev'
      ),
  
      //Live environment
      'www.mynewcraftsite.com.au' =&gt; array(
          'siteUrl' =&gt; 'www.dashingprint.com.au'
      )
  );
  </code></pre>
  
  <p>It works EXCEPT when I go to www.mynewcraftsite.dev and then click on the links, I end up back on www.mynewcraftsite.com.au (eg. Instead of going to www.mynewcraftsite.dev/services, I go to www.mynewcraftsite.com.au/services. In order to get to the correct page I gotta write up the whole url www.mynewcraftsite.dev/service into the google chrome url bar.)</p>
  
  <p>The siteURL property isn't doing anything, there's gotta be something else that I gotta stick in there in order to rewrite the urls.</p>
  
Tags: <config><database><multi-environment>
Title: How can I use multi-environment configuration to set each root URL?
ThreadText: # How can I use multi-environment configuration to set each root URL?
  
  (Asked by: username_0 on 2014-06-25)
  
  I'm building www.mynewcraftsite.com.au, but I also wanna create www.mynewcraftsite.dev which is a testing server to preview to my clients. I've heard that I can set this up with Craft without going through the drudgery of downloading/uploading databases and updating urls in the db, users ... etc.
  
  I've been reading the Craft CMS documentation for "Multi-Environment Configs". So far I've got this in my db.php file;
  
  ```
  return array(
      //All environments
      '*' => array(
          'omitScriptNameInUrls' => true,
          'localhost' or '127.0.0.1'.
          'server' => 'localhost',
          'user' => 'dashing-print',
          'password' => 'f#$njEwFRn3&2',
          'database' => 'dashing-print',
          'tablePrefix' => 'craft'
      ),
  
      //Testing environment
      'www.mynewcraftsite.dev' => array(
          'siteUrl' => 'www.dashingprint.dev'
      ),
  
      //Live environment
      'www.mynewcraftsite.com.au' => array(
          'siteUrl' => 'www.dashingprint.com.au'
      )
  );
  
  ```
  
  It works EXCEPT when I go to www.mynewcraftsite.dev and then click on the links, I end up back on www.mynewcraftsite.com.au (eg. Instead of going to www.mynewcraftsite.dev/services, I go to www.mynewcraftsite.com.au/services. In order to get to the correct page I gotta write up the whole url www.mynewcraftsite.dev/service into the google chrome url bar.)
  
  The siteURL property isn't doing anything, there's gotta be something else that I gotta stick in there in order to rewrite the urls.
  
  **Tags:** config, database, multi-environment
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2014-06-25. Score: 12
  
  Make sure to change the "Site URL" setting to `{siteUrl}` in your control panel settings...
  
  > Control Panel > Settings > General > "Site URL"
  
  Within your config file, you'll also want to put your `siteUrl` value inside of an [Environment-Specific Variables](http://buildwithcraft.com/docs/multi-environment-configs#environment-specific-variables) sub-array:
  
  ```
  'mynewcraftsite.dev' => array(
      'devMode' => true,
      'environmentVariables' => array(
          'siteUrl' => 'http://www.mynewcraftsite.dev/'
      )
  ),
  'mynewcraftsite.com.au' => array(
      'environmentVariables' => array(
          'siteUrl' => 'http://www.mynewcraftsite.com.au/'
      )
  )
  
  ```
  
  ---
  
  Here's how Craft is compiling all of that...
  
  Within each of your environment configurations, there are many [config settings](http://buildwithcraft.com/docs/config-settings) that you can apply to that specific environment. Additionally, each environment can have a sub-array called `environmentVariables`, which allows you to set whatever unique variables you want. The most common examples are `siteUrl` and `fileSystemPath` (great for setting up assets sources), but you can truly set whatever environment variables you want.
  
  Once you've set the `siteUrl` value in your environment variables array, you now need to use that value... This is where the control panel settings page comes into play. Changing "Site URL" to simply `{siteUrl}` tells Craft to pull that value from your environment variables.
  
  **IMPORTANT:** Notice the single set of curly braces, and the lack of spacing between the variable name and the braces. This is the syntax difference between **environment variables** and **Twig variables**.
  
  That's it! When you create a path, Craft will use whatever is in the "Site URL" setting. And since that's pulling in your environment variable, that's what you'll get.
  
  ---
  
  Lastly, allow me to point out a few things in your example which may also be stopping this from working for you (feel free to update the example in your question to fix these issues)...
  
  **Most importantly:** You're combining data that should be stored in two separate files... `craft/config/db.php` and `craft/config/general.php`. While the multi-environment format is the same, you'll need to separate the data shown in your example. Put most of your settings into `general.php`, only the following belong in `db.php`:
  
  * `server`
  * `user`
  * `password`
  * `database`
  * `tablePrefix`
  
  You also have an errant line of code in your example... This line should definitely be removed:
  
  ```
  'localhost' or '127.0.0.1'.
  
  ```
  
  Finally, you've left some crucial security information in your example... All of your database connection info is exposed (as well as your true domain names in your `siteUrl` examples).
  
  ---
  
  Hope that helps... If you fix the bugs in your example code, I'll remove my corresponding notes from this answer. :)
  
  
  ---
  
  ### Answer by username_2 on 2014-06-25. Score: 2
  
  The siteUrl value you are trying to set should not be set in the `db.php` file. It needs to be set in the `general.php` file. It also seems like you have a few other variables that should be moved over to `general.php` too.
  
  You have one line that needs to be removed completely or commented out. `'localhost' or '127.0.0.1'.` is not correct.
  
  **general.php**
  
  ```
  return array(
      //All environments
      '*' => array(
          'omitScriptNameInUrls' => true,
      )
  
      //Testing environment
      'www.mynewcraftsite.dev' => array(
          'environmentVariables' => array(
              'siteUrl' => 'http://www.mynewcraftsite.dev'
          )
      ),
  
      //Live environment
      'www.mynewcraftsite.com.au' => array(
          'environmentVariables' => array(
              'siteUrl' => 'http://www.mynewcraftsite.com.au'
          )
      )
  );
  
  ```
  
  **db.php**
  
  ```
  return array(
  
      //All environments
      '*' => array(
          'tablePrefix' => 'craft'
      ),
  
      //Testing environment
      'www.mynewcraftsite.dev' => array(
          'server' => 'localhost',
          'user' => 'testuser',
          'password' => 'testpassword',
          'database' => 'testdatabase'
      ),
  
      //Live environment
      'www.mynewcraftsite.com.au' => array(
          'server' => 'localhost',
          'user' => 'liveuser',
          'password' => 'livepassword',
          'database' => 'livedatabase'
      )
  );
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2016-12-04. Score: 1
  
  You might find this helpful: [Multi-Environment Config for Craft CMS](https://nystudio107.com/blog/multi-environment-config-for-craft-cms)
  
  
  ---
  
  