rewriteengine on
rewritecond %{https} !=on
rewriterule ^(.*)https://%{server,name}/$1[r,l]
<rewrite>
<rules>
<rule name=http redirect to https stopprocessing=true>
<match url=(.*) />
<conditions>
<add input={https} pattern=^off$ />
<add input={https,host} pattern=^(localhost) negate=true />
</conditions>
<action type=redirect url=https://{http,host}/{r:1} />
</rule>
</rules>
</rewrite>