1

I have a multi-domain setup where I run multiple one-pager sites from different domains. For development purposes, I have configured it to work like this:

dev has:

http://localhost/www.domain1.com
http://localhost/www.domain2.com

staging has:

https://stage.ourdomain.com/www.domain1.com
https://stage.ourdomain.com/www.domain2.com

and production has:

https://www.domain1.com
https://www.domain2.com

To achieve this with the same site configuration for all three envs, I have created an alias called @baseUrlPrefix that I use in the site configuration (as part of the base URL), so for each env they are set to:

dev: http://localhost
stage: https://stage.ourdomain.com
prod: https:

And for each site I do @baseUrlPrefix//www.domain1.com (etc)

This has all worked fine and all, but I ran into issues when my devs had to do testing from mobile devices, because their local environment would only respond to localhost URLs. So I made a change for our dev config, to do (inspired by https://github.com/craftcms/cms/issues/2486):

use yii\web\Request;
$request = new Request;
...
'@baseUrlPrefix' => $request->getHostInfo(),

Which has also worked, no problem up until I'm trying to upgrade craft (this works in 3.3.15-18), and onwards from 3.3.19 it seems, it throws because it can't find Yii. It seems like maybe the loading order has changed, or I'm doing something incredibly stupid. I read that @web is supposed to actually take care of this, which it also does, so using @web/www.domain1.com does work as intended, and I can overwrite that alias on production and set it to https:.

BUT, I also read that it's highly discouraged to use @web as siteUrl (https://craftcms.com/docs/3.x/sites.html#site-url) and I don't fully understand the implications of this, or if my use of an @alias is already suffering fromt he same cache poisoning bug?

1

As far as I know, using the @web alias is discouraged if its determined automatically (which is the default behavior).

If you override it with a hardcoded value in production I think you should be fine.


Edit

After checking the documentation, the warning is now pretty dissuasive against using the @web alias :

enter image description here

When you actually use it in a site's base URL setting in the control panel, the warning is a little more moderated:

enter image description here

I'm not sure if its because the documentation is more up to date or if it's actually fine to use it when overridden.

1
  • Yeah, it's highly confusing. I also feel like the cache poisoning bug should be fixable. – jishi Sep 14 '20 at 19:10

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.