我已经用Cloudflare DNS建立了我在Digital Ocean托管的网站,并希望将https重定向到所有子域,例如,当用户寻找[here时,它将自动重定向到http://]sub.exmple.com,因为它很好地适用于网站本身(exmple.com重定向到https://sub.exmple.com)
我的环境:带有Ubuntu 16.4服务器的Apache2,PHP7,MariaDB 我已经在Cloudflare和我的托管提供程序上都设置了通配符重定向的A记录到A | * .exmple.com | IP
由于Cloudflare不支持通配符SSL证书,因此我使用了允许使用Cloudflare API设置免费的Let's Encrypt通配符SSL的插件。 我也尝试使用.htaccess指令,但是,似乎Cloudflare设置会覆盖它。
# *** force https:// only if online
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTPS} off
RewriteCond %{ENV:HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]