<p>You are overcomplicating this a little bit. This is nothing more than a CORS issue, you can simply resolve this by adjusting your nginx or apache config to also allow the origins for the subdomain from your <code>www</code> subdomain.</p>

CC BY-SA 4.0
2023-05-17T14:29:41.093Z
I asked the server host to look into this but somehow there was no way.
In the end I ended up removing the `App::env('PRIMARY_SITE_URL') . ` from the setting so I always used the domain you're on.
svondervoort
CC BY-SA 4.0
2023-04-19T14:48:44.717Z
2023-04-19T14:48:44.717Z
Michael Thomas
<p>We have a multi-(sub)domain setup within a single Craft CMS and single <code>.env</code> file: <code>insights.xximo.com</code> and <code>www.xximo.com</code>.
Sometimes when visiting <code>insights.xximo.com</code> we get errors like:</p>
<pre><code>Access to script at 'https://www.xximo.com/dist/assets/app.089fed21.js' from origin 'https://insights.xximo.com' has been blocked by CORS policy:
The 'Access-Control-Allow-Origin' header has a value 'https://www.xximo.com' that is not equal to the supplied origin.
</code></pre>
<p>This is caused by the Craft-Vite plugin which in the <a href="https://github.com/nystudio107/craft-vite/blob/develop/src/config.php#L47" rel="nofollow noreferrer">config#47</a> uses <code>   'serverPublic' =&gt; App::env('PRIMARY_SITE_URL') . '/dist/'</code> to set the path to the assets.</p>
<p>I know there is a way to use different configurations depending on the <code>environment</code> but is there also a way to differentiate configurations depending the <code>site(handle)</code>?</p>
<p>I tried loading <code>craft\console\Application</code> into the config and using <code>Application-&gt;sites-&gt;currentSite-&gt;handle === 'insights' ? App::env('PRIMARY_SITE_URL') : App::env('INSIGHTS_SITE_URL')</code> but that doesn't seem to be allowed or working.</p>

<config><multi-site><multi-domain>
Multi-domain configuration
# Multi-domain configuration

(Asked by: username_0 on 2023-04-19)

We have a multi-(sub)domain setup within a single Craft CMS and single .env file: insights.xximo.com and www.xximo.com.
Sometimes when visiting insights.xximo.com we get errors like:
Access to script at 'https://www.xximo.com/dist/assets/app.089fed21.js' from origin 'https://insights.xximo.com' has been blocked by CORS policy:
The 'Access-Control-Allow-Origin' header has a value 'https://www.xximo.com' that is not equal to the supplied origin.

This is caused by the Craft-Vite plugin which in the config#47 uses    'serverPublic' => App::env('PRIMARY_SITE_URL') . '/dist/' to set the path to the assets.
I know there is a way to use different configurations depending on the environment but is there also a way to differentiate configurations depending the site(handle)?
I tried loading craft\console\Application into the config and using Application->sites->currentSite->handle === 'insights' ? App::env('PRIMARY_SITE_URL') : App::env('INSIGHTS_SITE_URL') but that doesn't seem to be allowed or working.

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

---

## 1 answers

### Answer by username_1 on 2023-04-19. Score: 1 | Accepted answer

You are overcomplicating this a little bit. This is nothing more than a CORS issue, you can simply resolve this by adjusting your nginx or apache config to also allow the origins for the subdomain from your `www` subdomain.

> **Comments:**
> **username_0**: I asked the server host to look into this but somehow there was no way. In the end I ended up removing the `App::env('PRIMARY_SITE_URL') . ` from the setting so I always used the domain you're on.  

---

