Language detection by domain breaks ajax requests over https What do I have:


Drupal 8.6.2 
Domain Access 
Language modules 
Cloudflare with https


Problem:

If in URL language detection option (/admin/config/regional/language/detection/url) I have "Path prefix" - everything works fine.

Party starts, when I change it to "Domain" - every ajax request on any subdomain is trying to get through http instead of https and I can see "mixed content error" in console, so these requests are being blocked and website is malfunctioning. I cant use views propeerly, upload files through Plupload, use autocomplete forms, change some settings etc.

If I change it back to prefix - ajax works great again.

For prefix I have site.com for default language and site.com/en - for english. For domain setting: site.com - default and en.site.com is english version.

In Domain Access settings I've tried to set all possible URL schemas (http, https and variable) - no change. In Cloudflare settings I have speacial rules, redirecting every request from http to https (I set up CF's https for dozen of websites, I know how to do it).

If I set back to prefix and go to en.site.com (it still works as an alias for the main domain) ajax works fine, so this is not something about server or background settings - it's just Drupal messing around.

I could run it with prefix, but for SEO purposes it is better to use subdomain, because website is going to be big and it is better to separate languages technically on different websites, search engines will rank these subdomains more correct.

Please help! This is my first experience with multilingual website and I don't have a clue what to do.
The problem is the CDN, which connects to Drupal via HTTP and to the client via HTTPS. Then all absolute URLs generated by Drupal have the wrong protocol. Not only this one for ajax, which is absolute because you've switched language detection to domain based. Prefix based it uses relative paths and then the protocol doesn't matter.

Normally CDN's add a header X_FORWARDED_PROTO to the request, which Drupal can use to determine the correct protocol. For this to work you have to configure the CDN as reverse proxy in settings.php.