<p>You could achieve this using <a href="https://docs.craftcms.com/v3/config/#aliases" rel="nofollow noreferrer">Aliases</a>.</p>
<p>In your <code>.env</code>, you could set <code>DEFAULT_DOMAIN=&quot;yourdomain.com&quot;</code> then in your <code>config/general.php</code> you would do:</p>
<pre><code>'aliases' =&gt; [
    'siteAbc' =&gt; 'http://abc.' . getenv('DEFAULT_DOMAIN'),
    'siteXyz' =&gt; 'http://xyz.' . getenv('DEFAULT_DOMAIN')
],
</code></pre>
<p>With this in place, you will be able to use <code>@siteAbc</code> and <code>@siteXyz</code> to set your site URL as well as <code>@siteAbc/images</code> for your assets Base URL for example...</p>
<p>Note that all naming convention is up to you, of course...</p>

CC BY-SA 4.0
2020-07-14T04:32:10.293Z
Thanks. I looked at aliases but didnt quite think about it that way. It'll take a code change to add a new site, but it already does, so what's one more :)
Josh Coady
CC BY-SA 4.0
2020-07-13T12:02:56.393Z
2020-07-13T12:02:56.393Z
Oli
<p>For example, let's say I have two sites: abc.example.com and xyz.example.com but I want to also host test versions of those sites at example-test.com.</p>
<p>It'd be nice if I could set the baseURLs to http://abc.$DOMAIN and http://xyz.$DOMAIN and then set the env var DOMAIN on the server (or something similar), but Craft currently only supports setting base URL to an env var if that is the entirety of what it is set to.</p>
<p>I'm not interested in creating an env var per subdomain.</p>
<p>Any ideas?</p>

<config><multi-site><project.yaml>
How can I configure multi-site base URLs where the subdomains are static but the domain name is dynamic?
# How can I configure multi-site base URLs where the subdomains are static but the domain name is dynamic?

(Asked by: username_0 on 2020-07-12)

For example, let's say I have two sites: abc.example.com and xyz.example.com but I want to also host test versions of those sites at example-test.com.

It'd be nice if I could set the baseURLs to http://abc.$DOMAIN and http://xyz.$DOMAIN and then set the env var DOMAIN on the server (or something similar), but Craft currently only supports setting base URL to an env var if that is the entirety of what it is set to.

I'm not interested in creating an env var per subdomain.

Any ideas?

**Tags:** config, multi-site, project.yaml


---

## 1 answers

### Answer by username_1 on 2020-07-13. Score: 2 | Accepted answer

You could achieve this using Aliases.
In your .env, you could set DEFAULT_DOMAIN="yourdomain.com" then in your config/general.php you would do:
'aliases' => [
    'siteAbc' => 'http://abc.' . getenv('DEFAULT_DOMAIN'),
    'siteXyz' => 'http://xyz.' . getenv('DEFAULT_DOMAIN')
],

With this in place, you will be able to use @siteAbc and @siteXyz to set your site URL as well as @siteAbc/images for your assets Base URL for example...
Note that all naming convention is up to you, of course...

> **Comments:**
> **username_0**: Thanks. I looked at aliases but didnt quite think about it that way. It'll take a code change to add a new site, but it already does, so what's one more :)  

---

