<p>We're working a multisite project where the individual sites have different domains. We want to have a simple setup where both sites share an asset folder (<code>web/cms-assets</code>). So far, we're looking at the approach <a href="https://nystudio107.com/blog/multi-environment-configuration-for-craft-cms-3#multi-site-multi-environment-in-craft-cms" rel="nofollow noreferrer">detailed here</a>:</p>
<pre><code># .env
SITE_ONE_URL=https://site-one.com/
SITE_TWO_URL=https://site-two.com/
</code></pre>
<pre class="lang-php prettyprint-override"><code>// config/general.php
'aliases' =&gt; [
    '@siteOneUrl' =&gt; getenv('SITE_ONE_URL'),
    '@siteTwoUrl' =&gt; getenv('SITE_TWO_URL'),
],
</code></pre>
<p>Then use those aliases for the <code>baseUrl</code> setting for the two sites. Now the problem is that now the <code>@web</code> alias is not defined, so Craft infers it from the request. The docs are pretty clear that this is not recommmended. So we would need a way to define the <code>@web</code> alias based on the current site's URL. One approach would be to check the current URL and set the alias to the matching domain based on that in <code>config/general.php</code> – but that feels wrong, and it doesn't work for console requests. Another problem are asset URLs – currently, the asset volume's base URL is set to <code>@web/cms-assets/</code>. We'd like for this to resolve to an absolute URL with the URL of the current site, but this means settings the <code>@web</code> alias based on the current URL again.</p>
<p>Is there a way to set the <code>@web</code> alias based on the current site's <code>baseUrl</code>? Or are we approaching this in the wrong way? What would be the standard/recommended way to approach this?</p>

CC BY-SA 4.0
2022-07-22T15:27:01.380Z
Maybe I'm missing something, what's wrong with setting `@web` to an empty string in general.php? I'm not using it for anything. Asset paths can start with `@siteOneUrl`/`@siteTwoUrl` if you want absolute URLs, but often I just use a symlink instead so that I can use site-root relative paths.
James Smith
CC BY-SA 4.0
2022-07-22T15:38:47.133Z
@JamesSmith Currently we have `@web` set to `/`, so everything using it will use absolute paths relative to the current URL. This should work for the asset URLs at least. IIRC some console commands require an URL for the `@web` though, or am I misremembering something?
MoritzLost
CC BY-SA 4.0
2022-07-22T17:36:34.363Z
I have a note to myself in a multi site project that asset (re)indexing via the console requires a full base path (the filesystem path) to work properly, but not necessarily a full URL. So I also abstracted the base path to env vars.
James Smith
CC BY-SA 4.0
2022-07-24T11:20:50.920Z
@JamesSmith Thanks for the insights, I'll test that out next week!
MoritzLost
<multi-site><multi-domain><alias>
@web alias in multisite setup with different domains
# @web alias in multisite setup with different domains

(Asked by: username_0 on 2022-07-21)

We're working a multisite project where the individual sites have different domains. We want to have a simple setup where both sites share an asset folder (web/cms-assets). So far, we're looking at the approach detailed here:
# .env
SITE_ONE_URL=https://site-one.com/
SITE_TWO_URL=https://site-two.com/

// config/general.php
'aliases' => [
    '@siteOneUrl' => getenv('SITE_ONE_URL'),
    '@siteTwoUrl' => getenv('SITE_TWO_URL'),
],

Then use those aliases for the baseUrl setting for the two sites. Now the problem is that now the @web alias is not defined, so Craft infers it from the request. The docs are pretty clear that this is not recommmended. So we would need a way to define the @web alias based on the current site's URL. One approach would be to check the current URL and set the alias to the matching domain based on that in config/general.php – but that feels wrong, and it doesn't work for console requests. Another problem are asset URLs – currently, the asset volume's base URL is set to @web/cms-assets/. We'd like for this to resolve to an absolute URL with the URL of the current site, but this means settings the @web alias based on the current URL again.
Is there a way to set the @web alias based on the current site's baseUrl? Or are we approaching this in the wrong way? What would be the standard/recommended way to approach this?

**Tags:** multi-site, multi-domain, alias

> **Comments:**
> **username_1**: Maybe I'm missing something, what's wrong with setting `@web` to an empty string in general.php? I'm not using it for anything. Asset paths can start with `@siteOneUrl`/`@siteTwoUrl` if you want absolute URLs, but often I just use a symlink instead so that I can use site-root relative paths.  
> **username_0**: @JamesSmith Currently we have `@web` set to `/`, so everything using it will use absolute paths relative to the current URL. This should work for the asset URLs at least. IIRC some console commands require an URL for the `@web` though, or am I misremembering something?  
> **username_1**: I have a note to myself in a multi site project that asset (re)indexing via the console requires a full base path (the filesystem path) to work properly, but not necessarily a full URL. So I also abstracted the base path to env vars.  
> **username_0**: @JamesSmith Thanks for the insights, I'll test that out next week!  

---

## 0 answers

