Well, that's what I thought would happen, as I explained in the closing paragraph of my previous post. We cannot let you add stuff to the .htaccess file before the HSTS block since that would allow bypass of HTTPS in some cases which can be used for a successful cookie-stealing attack. That was a real issue that we fixed a few months ago. This is why the rules at the top of the file are added just below the rules which enforce HTTPS for all requests. We cannot reverse that decision, it creates an unsafe situation. Between making a change that addresses one broken hosts but puts hundreds of thousands of other sites at risk and keeping a change that requires you to manually edit your file but keeps hundreds of thousands of other sites safe I will choose the latter any day of the week, hands down, without any regret whatsoever.
The problem seems to be your host. They are not sending X-Forwarded-Proto at all for HTTP requests.
This is wrong. Your host needs to fix it. I don't know what kind of SSL terminator they use in front of Varnish (I'd guess NginX) so I can't tell you what to tell them. If it's NginX they have two configuration blocks, one for HTTPS and one for HTTP. They need to edit the "location /" block in both places and add proxy_set_header X-Forwarded-Proto https; to the HTTPS one and proxy_set_header X-Forwarded-Proto http; to the plain HTTP one. This fixes the issue.
Meanwhile, you will have to edit the file by hand every time you generate it.
You may wonder why not change
RewriteCond %{HTTP:X-Forwarded-Proto} =http
with
RewriteCond %{HTTP:X-Forwarded-Proto} !https
It's because the latter allows spoofing of the HTTP header on hosts which do not use a cache or proxy in front of them, putting them at risk.
Nicholas K. Dionysopoulos
Lead Developer and Director
🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!