gpt4 book ai didi

apache - 使用 .htaccess 将 http 流量重定向到 https

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:10 25 4
gpt4 key购买 nike

我正在尝试将所有 http 流量重定向到 https。我没有在我的服务器上安装 SSL 证书,而是使用 cloudflare 灵活的 SSL 选项。

以下代码工作文件

  RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

但这会重定向 http://www.example.comhttps://example.com

但是当我添加这个

RewriteCond %{HTTP_HOST} ^(.*)
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

重定向所有非 www url,例如 http://example.comhttps://example.com

该网站无法加载,并在浏览器上给我一个错误消息,显示太多重定向。我该如何解决这个问题并将我所有的 http 流量重定向到 https://?

谢谢

最佳答案

如果您的服务器上没有 SSL 证书,您必须将 CloudFlare SSL 设置为“灵活”。

根据他们的 blog post然后,您可以在 .htaccess 中设置以下内容:

RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]

您当前的设置会检查请求是否通过 https 到达您的 服务器,但由于您没有证书,因此无法正常工作。 CloudFlare 将所有 https 请求转发到 http,然后您的服务器重定向到 https,依此类推。

关于apache - 使用 .htaccess 将 http 流量重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32502466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com