Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-14T04:32:10.293Z
Answers.Text: 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 :)
Answers.UserDisplayName: Josh Coady
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-13T12:02:56.393Z
Answers.LastActivityDate: 2020-07-13T12:02:56.393Z
Answers.UserDisplayName: Oli
Body: <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>
  
Tags: <config><multi-site><project.yaml>
Title: How can I configure multi-site base URLs where the subdomains are static but the domain name is dynamic?
ThreadText: # 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](https://docs.craftcms.com/v3/config/#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 :)  
  
  ---
  
  