.htaccess - 如何使用 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]
解决方案
推荐阅读
- python - 更改导入库的环境变量
- ruby-on-rails - 当某个模型中没有记录时,rails 会创建两次
- java - 在java windowbuilder中添加动态复选框
- wordpress - 新版 WordPress 插件未反映
- python - Python 3.5 与 2.7 之间字符串连接的巨大时间差异
- amazon-web-services - 具有 2 个 AWS 账户的 AWS CodePipeline 最佳实践
- android - 保存 Viewpager 中片段中存在的 Recyclerview 状态
- oracle - 如何在 oracle 中设置 remote_listener
- sql - 在 postgresql 上选择 LIMIT 1 需要很长时间
- javascript - 如何选择只有特定类的元素?