TransWikia.com

Loading assets cross-domain with SSL or non-SSL option

Craft CMS Asked on July 8, 2021

Here’s a unique situation. I have three websites. All assets are stored at the domain of the first site:
domain.com/files/*

The first two sites run completely over SSL. No problem.
The third site needs to have the option to load either over SSL or non-SSL. This is entirely thanks to the authoritarian governments of countries like China, which may block a site, no matter the content, if it can only load over SSL.

In my config.php, I have this:

'@assetBaseUrl' => 'https://site1.domain.org/files'

If I change this to exclude https://, Craft does not create proper URLs for images and files. I also tried //site1.domain.org, but that doesn’t work either.

Is there some setting I can use for @assetBaseUrl that will work across the board?

One Answer

You could try something like '@assetBaseUrl' => $_SERVER['HTTPS'] ? 'https://site1.domain.org/files' : 'http://site1.domain.org/files' which checks for a secure request.

Correct answer by dmatthams on July 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP