首页 > 解决方案 > 如何使用 Cloudflare DNS 重定向通配符子域并将 SSL 加密为 HTTPS 版本?

问题描述

我已经使用 Cloudflare DNS 设置了我的 Digital Ocean 托管网站,并希望将 https 重定向到所有子域,例如当用户查找 [ http://]sub.exmple.com时,自动重定向到https:// sub.exmple.com,因为它很好地适用于网站本身(exmple.com 重定向到https://exmple.com

我的环境:Apache2 和 Ubuntu 16.4 服务器、PHP7、MariaDB 我已经在 Cloudflare 和我的托管服务提供商上设置了通配符重定向的 A 记录。*.example.com | 知识产权

在此处输入图像描述

由于 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]

我做错了什么,我有什么选择? 在此处输入图像描述

标签: .htaccessdnscloudflarehttp-redirectwildcard-subdomain

解决方案


推荐阅读