Answers.Body: <p>As happens, I had to "give up" and ask for help in order to figure out a solution myself.</p>
  
  <p>My issue was I was trying to dynamically set <code>@web</code> and <code>@webroot</code> for the sake of Asset Volumes. That would presumably mess up other things that use those aliases.</p>
  
  <p>A way to make it work is to create new aliases per-site for Asset Volumes. If someone else wants to do this, here is a way.</p>
  
  <p>In <code>config/general.php</code> create aliases in the appropriate spot (e.g. in the <code>*</code> global, <code>dev</code> or whatever environment section you want) replacing <code>&lt;site-handle&gt;</code> with the handle of your site (set in the Settings > Sites panel):</p>
  
  <pre><code>'aliases' =&gt; [
    '@&lt;site-handle&gt;AssetsBaseUrl' =&gt; 'https://site-a.dev',
    '@&lt;site-handle&gt;AssetsBasePath' =&gt; '/Users/kirkroberts/Work/Codebases/site-a.com/online/public_html',
  ]
  </code></pre>
  
  <p>Now for the Asset Volumes for that particular site you can use <code>@&lt;site-handle&gt;AssetsBaseUrl</code> or <code>@&lt;site-handle&gt;AssetsBaseUrl</code> to start your Base URL and File System Path fields, respectively. (replacing <code>&lt;site-handle&gt;</code> with that Site's handle)</p>
  
  <p>This should enable assets to be stored in whatever domain/folder you specify.</p>
  
  <p>Of course, the aliases will need to be set manually for each environment in <code>config/general.php</code>, which is kind of a pain but not a huge deal.</p>
  
  <p>Maybe that will help someone get it done or find an even better way to do it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-17T16:02:21.857Z
Answers.LastActivityDate: 2019-12-18T15:34:31.770Z
Answers.LastEditDate: 2019-12-18T15:34:31.770Z
Answers.UserDisplayName: Kirk Roberts
Body: <p>There must be a simple answer for this but despite fumbling around with it for quite a while and searching the web for answers I am stymied. Perhaps I'm approaching it in the wrong way. I'm feeling like a beginner and I may not be using the right terminology here.</p>
  
  <p>Here is a similar question without an accepted answer: <a href="https://craftcms.stackexchange.com/questions/27628/how-to-setup-assets-in-multi-site-where-each-site-should-have-its-own-assets">How to setup assets in multi site where each site should have its own assets?</a></p>
  
  <p>I have two sites, Site A and Site B, with their own assets folder. They are separate sites that will not share assets at all and it would be ideal to keep them completely separate (just as the templates are separated in folders with each Site's handle).</p>
  
  <pre><code>/site-a
  -- /site-a-assets
  /site-b
  -- /site-b-assets
  </code></pre>
  
  <p>I've seen that <code>@web</code> should not be used for Asset Volumes' Base URL when using multi-site, but I haven't been able to understand how to set up <code>config/default.php</code> to accommodate different addresses for different sites AND different environments (e.g. dev, production). I've seen mention of using aliases but don't understand yet how to make them work with multiple sites to have different values for the same alias depending on which site you're viewing and in which environment.</p>
  
  <p>I have this for my local <code>siteUrl</code> in <code>config/default.php</code> inside of environment settings:</p>
  
  <pre><code>'siteUrl' =&gt; [
    'site-a' =&gt; 'https://org.site-a',
    'site-b' =&gt; 'https://org.site-b',
  ]
  </code></pre>
  
  <p>It feels like I'm close but I can't get the pieces put together.</p>
  
  <p>Any pointers you can give will be greatly appreciated!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-17T15:35:35.933Z
Comments.Text: I'm realizing this is probably not possible to do dynamically because the CP may/should be accessed from a certain domain/path. That means that any "other" site's Asset Volumes will use the "main" site's domain/path if set dynamically (assuming the "main" site's domain is used to access the CP. So, probably need to have a central assets repository for all sites, perhaps with subfolders per-site. I'd love to be shown that I'm wrong that that is the only way to do it.
Comments.UserDisplayName: Kirk Roberts
Tags: <assets><multi-site><alias>
Title: How do I dynamically define Asset Volumes' Base URLs for different Sites?
ThreadText: # How do I dynamically define Asset Volumes' Base URLs for different Sites?
  
  (Asked by: username_0 on 2019-12-16)
  
  There must be a simple answer for this but despite fumbling around with it for quite a while and searching the web for answers I am stymied. Perhaps I'm approaching it in the wrong way. I'm feeling like a beginner and I may not be using the right terminology here.
  
  Here is a similar question without an accepted answer: [How to setup assets in multi site where each site should have its own assets?](https://craftcms.stackexchange.com/questions/27628/how-to-setup-assets-in-multi-site-where-each-site-should-have-its-own-assets)
  
  I have two sites, Site A and Site B, with their own assets folder. They are separate sites that will not share assets at all and it would be ideal to keep them completely separate (just as the templates are separated in folders with each Site's handle).
  
  ```
  /site-a
  -- /site-a-assets
  /site-b
  -- /site-b-assets
  
  ```
  
  I've seen that `@web` should not be used for Asset Volumes' Base URL when using multi-site, but I haven't been able to understand how to set up `config/default.php` to accommodate different addresses for different sites AND different environments (e.g. dev, production). I've seen mention of using aliases but don't understand yet how to make them work with multiple sites to have different values for the same alias depending on which site you're viewing and in which environment.
  
  I have this for my local `siteUrl` in `config/default.php` inside of environment settings:
  
  ```
  'siteUrl' => [
    'site-a' => 'https://org.site-a',
    'site-b' => 'https://org.site-b',
  ]
  
  ```
  
  It feels like I'm close but I can't get the pieces put together.
  
  Any pointers you can give will be greatly appreciated!
  
  **Tags:** assets, multi-site, alias
  
  > **Comments:**
  > **username_0**: I'm realizing this is probably not possible to do dynamically because the CP may/should be accessed from a certain domain/path. That means that any "other" site's Asset Volumes will use the "main" site's domain/path if set dynamically (assuming the "main" site's domain is used to access the CP. So, probably need to have a central assets repository for all sites, perhaps with subfolders per-site. I'd love to be shown that I'm wrong that that is the only way to do it.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-12-17. Score: 3 | Accepted answer
  
  As happens, I had to "give up" and ask for help in order to figure out a solution myself.
  
  My issue was I was trying to dynamically set `@web` and `@webroot` for the sake of Asset Volumes. That would presumably mess up other things that use those aliases.
  
  A way to make it work is to create new aliases per-site for Asset Volumes. If someone else wants to do this, here is a way.
  
  In `config/general.php` create aliases in the appropriate spot (e.g. in the `*` global, `dev` or whatever environment section you want) replacing `<site-handle>` with the handle of your site (set in the Settings > Sites panel):
  
  ```
  'aliases' => [
    '@<site-handle>AssetsBaseUrl' => 'https://site-a.dev',
    '@<site-handle>AssetsBasePath' => '/Users/username_0/Work/Codebases/site-a.com/online/public_html',
  ]
  
  ```
  
  Now for the Asset Volumes for that particular site you can use `@<site-handle>AssetsBaseUrl` or `@<site-handle>AssetsBaseUrl` to start your Base URL and File System Path fields, respectively. (replacing `<site-handle>` with that Site's handle)
  
  This should enable assets to be stored in whatever domain/folder you specify.
  
  Of course, the aliases will need to be set manually for each environment in `config/general.php`, which is kind of a pain but not a huge deal.
  
  Maybe that will help someone get it done or find an even better way to do it.
  
  
  ---
  
  