Answers.Body: <p>You have to use aliases in order to make that work <a href="http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html" rel="nofollow noreferrer">Docs</a></p>
  
  <p>In your config (just a snipped from us, we don't insert the links and folders manually and use the <code>$_SERVER</code> variables to generate them) </p>
  
  <pre><code>'aliases' =&gt; [
      'assetPath' =&gt; $publicPath . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR,
      'assetUrl'  =&gt; $server . 'assets/',
      'basePath'  =&gt; $publicPath . DIRECTORY_SEPARATOR,
      'baseUrl'   =&gt; $server,
  ],
  </code></pre>
  
  <p>So you can insert something like </p>
  
  <pre><code>@assetPath/general
  </code></pre>
  
  <p>as your base volume path or for your sites</p>
  
  <pre><code>@baseUrl/en/
  </code></pre>
  
  <p>those aliases will be parsed automatically</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T09:10:00.767Z
Answers.Text: Thank you! The at sign (@) writting is working fine for my assets' base URL volumes. But this is not working for my sites' base URL: http://@baseUrl/international/en/ in settings → I get http://baseurl/international/en/ in front-end. Also for sites, is it possible to set a dynamic base URL protocol using a variable? Because if http(s):// is deleted in profit of the at sign (@) variable, after Save an http is automatically added at the beginning of this URL.
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-11T13:11:54.990Z
Answers.LastActivityDate: 2018-01-11T13:11:54.990Z
Answers.UserDisplayName: Robin Schambach
Answers.Body: <p>So as of <a href="https://github.com/craftcms/cms/blob/develop/CHANGELOG-v3.md#300-rc7---2018-01-23" rel="noreferrer">Craft CMS 3 RC7</a>, they added a new <code>alias()</code> Twig function.</p>
  
  <p>So what you can do is something like this in your <code>general.php</code>:</p>
  
  <pre><code>'aliases' =&gt; [
      '@basePath' =&gt; getenv('CRAFTENV_BASE_PATH'),
      '@baseUrl' =&gt; getenv('CRAFTENV_BASE_URL'),
  ],
  </code></pre>
  
  <p>(or whatever/however you want to set them). These aliases can be used in sites’ Base URL settings, volumes’ Base URL settings, and Local volumes’ File System Path settings in the AdminCP.</p>
  
  <p>And then in your templates, you can do something like:</p>
  
  <pre><code>{{ alias('@baseUrl') }}
  {{ alias('@baseUrl/assets/img/' }}
  </code></pre>
  
  <p>To resolve the alias there. I changed <a href="https://github.com/nystudio107/craft3-multi-environment" rel="noreferrer">Craft 3 Multi-Environment</a> to leverage aliases in this way (rather than having them in the <code>.custom</code> config), and it's documented in detail in the <a href="https://github.com/nystudio107/craft3-multi-environment#asset-volumes-and-aliases" rel="noreferrer">Asset Volumes and Aliases</a>.</p>
  
  <p>You do not need to be using Craft 3 Multi-Environment to utilize them in the same way, this is just a live example that's handy to point to.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-01T19:07:04.920Z
Answers.LastActivityDate: 2018-02-01T19:17:55.277Z
Answers.LastEditDate: 2018-02-01T19:17:55.277Z
Answers.UserDisplayName: andrew.welch
Body: <p>Sites localized versions are setup using <em>Base URL</em> like this:</p>
  
  <pre><code>— http://{baseUrl}/en/
  — http://{baseUrl}/fr/
  </code></pre>
  
  <p>But <code>{baseUrl}</code> variables are not transformed using <code>craft.app.sites.getAllSites()</code>. </p>
  
  <pre><code>{% set sites = craft.app.sites.getAllSites() %}
  {% for site in sites %}
      {{ site.baseUrl }}
      // → outputs http://{baseUrl}/locale/ instead of http://mywebsite.com/en/
  {% endfor %}
  </code></pre>
  
  <p>Whereas <code>baseUrl</code> are set from general.php:</p>
  
  <pre><code>'aliases' =&gt; array(
      'basePath' =&gt; '/mywebsite.com/htdocs/',
      'baseUrl'  =&gt; 'http://www.mywebsite.com/'
  ),
  </code></pre>
  
Tags: <localization><config><craft3><multi-site>
Title: Craft 3: how can I set dynamic Base URL in sites setting?
ThreadText: # Craft 3: how can I set dynamic Base URL in sites setting?
  
  (Asked by: username_0 on 2018-01-10)
  
  Sites localized versions are setup using *Base URL* like this:
  
  ```
  — http://{baseUrl}/en/
  — http://{baseUrl}/fr/
  
  ```
  
  But `{baseUrl}` variables are not transformed using `craft.app.sites.getAllSites()`.
  
  ```
  {% set sites = craft.app.sites.getAllSites() %}
  {% for site in sites %}
      {{ site.baseUrl }}
      // → outputs http://{baseUrl}/locale/ instead of http://mywebsite.com/en/
  {% endfor %}
  
  ```
  
  Whereas `baseUrl` are set from general.php:
  
  ```
  'aliases' => array(
      'basePath' => '/mywebsite.com/htdocs/',
      'baseUrl'  => 'http://www.mywebsite.com/'
  ),
  
  ```
  
  **Tags:** localization, config, craft3, multi-site
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-02-01. Score: 8 | Accepted answer
  
  So as of [Craft CMS 3 RC7](https://github.com/craftcms/cms/blob/develop/CHANGELOG-v3.md#300-rc7---2018-01-23), they added a new `alias()` Twig function.
  
  So what you can do is something like this in your `general.php`:
  
  ```
  'aliases' => [
      '@basePath' => getenv('CRAFTENV_BASE_PATH'),
      '@baseUrl' => getenv('CRAFTENV_BASE_URL'),
  ],
  
  ```
  
  (or whatever/however you want to set them). These aliases can be used in sites’ Base URL settings, volumes’ Base URL settings, and Local volumes’ File System Path settings in the AdminCP.
  
  And then in your templates, you can do something like:
  
  ```
  {{ alias('@baseUrl') }}
  {{ alias('@baseUrl/assets/img/' }}
  
  ```
  
  To resolve the alias there. I changed [Craft 3 Multi-Environment](https://github.com/nystudio107/craft3-multi-environment) to leverage aliases in this way (rather than having them in the `.custom` config), and it's documented in detail in the [Asset Volumes and Aliases](https://github.com/nystudio107/craft3-multi-environment#asset-volumes-and-aliases).
  
  You do not need to be using Craft 3 Multi-Environment to utilize them in the same way, this is just a live example that's handy to point to.
  
  
  ---
  
  ### Answer by username_1 on 2018-01-11. Score: 1
  
  You have to use aliases in order to make that work [Docs](http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html)
  
  In your config (just a snipped from us, we don't insert the links and folders manually and use the `$_SERVER` variables to generate them)
  
  ```
  'aliases' => [
      'assetPath' => $publicPath . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR,
      'assetUrl'  => $server . 'assets/',
      'basePath'  => $publicPath . DIRECTORY_SEPARATOR,
      'baseUrl'   => $server,
  ],
  
  ```
  
  So you can insert something like
  
  ```
  @assetPath/general
  
  ```
  
  as your base volume path or for your sites
  
  ```
  @baseUrl/en/
  
  ```
  
  those aliases will be parsed automatically
  
  > **Comments:**
  > **username_0**: Thank you! The at sign (@) writting is working fine for my assets' base URL volumes. But this is not working for my sites' base URL: http://@baseUrl/international/en/ in settings → I get http://baseurl/international/en/ in front-end. Also for sites, is it possible to set a dynamic base URL protocol using a variable? Because if http(s):// is deleted in profit of the at sign (@) variable, after Save an http is automatically added at the beginning of this URL.  
  
  ---
  
  