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?

1 Answer 1


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...

  • 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 :) Jul 14, 2020 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.