Answers.Body: <p>As far as I know, using the <code>@web</code> alias is discouraged if its determined automatically (which is the default behavior).</p>
  <p>If you override it with a hardcoded value in production I think you should be fine.</p>
  <hr />
  <h2>Edit</h2>
  <p>After checking <a href="https://craftcms.com/docs/3.x/sites.html#site-url" rel="nofollow noreferrer">the documentation</a>, the warning is now pretty dissuasive against using the <code>@web</code> alias :</p>
  <p><a href="https://i.sstatic.net/gNDS3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gNDS3.png" alt="enter image description here" /></a></p>
  <p>When you actually use it in a site's base URL setting in the control panel, the warning is a little more moderated:</p>
  <p><a href="https://i.sstatic.net/lotGR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lotGR.png" alt="enter image description here" /></a></p>
  <p>I'm not sure if its because the documentation is more up to date or if it's actually fine to use it when overridden.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-14T19:10:19.463Z
Answers.Text: Yeah, it's highly confusing. I also feel like the cache poisoning bug should be fixable.
Answers.UserDisplayName: jishi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-14T17:51:07.550Z
Answers.LastActivityDate: 2020-09-14T17:56:54.837Z
Answers.LastEditDate: 2020-09-14T17:56:54.837Z
Answers.UserDisplayName: nstCactus
Body: <p>I have a multi-domain setup where I run multiple one-pager sites from different domains. For development purposes, I have configured it to work like this:</p>
  <p>dev has:</p>
  <pre><code>http://localhost/www.domain1.com
  http://localhost/www.domain2.com
  </code></pre>
  <p>staging has:</p>
  <pre><code>https://stage.ourdomain.com/www.domain1.com
  https://stage.ourdomain.com/www.domain2.com
  </code></pre>
  <p>and production has:</p>
  <pre><code>https://www.domain1.com
  https://www.domain2.com
  </code></pre>
  <p>To achieve this with the same site configuration for all three envs, I have created an alias called <code>@baseUrlPrefix</code> that I use in the site configuration (as part of the base URL), so for each env they are set to:</p>
  <pre><code>dev: http://localhost
  stage: https://stage.ourdomain.com
  prod: https:
  </code></pre>
  <p>And for each site I do <code>@baseUrlPrefix//www.domain1.com</code> (etc)</p>
  <p>This has all worked fine and all, but I ran into issues when my devs had to do testing from mobile devices, because their local environment would only respond to localhost URLs. So I made a change for our dev config, to do (inspired by <a href="https://github.com/craftcms/cms/issues/2486" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/2486</a>):</p>
  <pre><code>use yii\web\Request;
  $request = new Request;
  ...
  '@baseUrlPrefix' =&gt; $request-&gt;getHostInfo(),
  </code></pre>
  <p>Which has also worked, no problem up until I'm trying to upgrade craft (this works in 3.3.15-18), and onwards from 3.3.19 it seems, it throws because it can't find Yii. It seems like maybe the loading order has changed, or I'm doing something incredibly stupid. I read that @web is supposed to actually take care  of this, which it also does, so using <code>@web/www.domain1.com</code> does work as intended, and I can overwrite that alias on production and set it to <code>https:</code>.</p>
  <p>BUT, I also read that it's highly discouraged to use @web as siteUrl (<a href="https://craftcms.com/docs/3.x/sites.html#site-url" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/sites.html#site-url</a>) and I don't fully understand the implications of this, or if my use of an @alias is already suffering fromt he same cache poisoning bug?</p>
  
Tags: <config><multi-site><multi-environment><multi-domain>
Title: How can I set an alias dynamically based on request?
ThreadText: # How can I set an alias dynamically based on request?
  
  (Asked by: username_0 on 2020-09-10)
  
  I have a multi-domain setup where I run multiple one-pager sites from different domains. For development purposes, I have configured it to work like this:
  
  dev has:
  
  ```
  http://localhost/www.domain1.com
  http://localhost/www.domain2.com
  
  ```
  
  staging has:
  
  ```
  https://stage.ourdomain.com/www.domain1.com
  https://stage.ourdomain.com/www.domain2.com
  
  ```
  
  and production has:
  
  ```
  https://www.domain1.com
  https://www.domain2.com
  
  ```
  
  To achieve this with the same site configuration for all three envs, I have created an alias called `@baseUrlPrefix` that I use in the site configuration (as part of the base URL), so for each env they are set to:
  
  ```
  dev: http://localhost
  stage: https://stage.ourdomain.com
  prod: https:
  
  ```
  
  And for each site I do `@baseUrlPrefix//www.domain1.com` (etc)
  
  This has all worked fine and all, but I ran into issues when my devs had to do testing from mobile devices, because their local environment would only respond to localhost URLs. So I made a change for our dev config, to do (inspired by <https://github.com/craftcms/cms/issues/2486>):
  
  ```
  use yii\web\Request;
  $request = new Request;
  ...
  '@baseUrlPrefix' => $request->getHostInfo(),
  
  ```
  
  Which has also worked, no problem up until I'm trying to upgrade craft (this works in 3.3.15-18), and onwards from 3.3.19 it seems, it throws because it can't find Yii. It seems like maybe the loading order has changed, or I'm doing something incredibly stupid. I read that @web is supposed to actually take care of this, which it also does, so using `@web/www.domain1.com` does work as intended, and I can overwrite that alias on production and set it to `https:`.
  
  BUT, I also read that it's highly discouraged to use @web as siteUrl (<https://craftcms.com/docs/3.x/sites.html#site-url>) and I don't fully understand the implications of this, or if my use of an @alias is already suffering fromt he same cache poisoning bug?
  
  **Tags:** config, multi-site, multi-environment, multi-domain
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-14. Score: 1
  
  As far as I know, using the `@web` alias is discouraged if its determined automatically (which is the default behavior).
  
  If you override it with a hardcoded value in production I think you should be fine.
  
  ---
  
  ## Edit
  
  After checking [the documentation](https://craftcms.com/docs/3.x/sites.html#site-url), the warning is now pretty dissuasive against using the `@web` alias :
  
  [![enter image description here](https://i.sstatic.net/gNDS3.png)](https://i.sstatic.net/gNDS3.png)
  
  When you actually use it in a site's base URL setting in the control panel, the warning is a little more moderated:
  
  [![enter image description here](https://i.sstatic.net/lotGR.png)](https://i.sstatic.net/lotGR.png)
  
  I'm not sure if its because the documentation is more up to date or if it's actually fine to use it when overridden.
  
  > **Comments:**
  > **username_0**: Yeah, it's highly confusing. I also feel like the cache poisoning bug should be fixable.  
  
  ---
  
  