【问题标题】:http to https giving redirect loop errorhttp 到 https 给出重定向循环错误
【发布时间】:2015-10-04 09:49:25
【问题描述】:

在我的 .htaccess 文件中:

 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

当我访问 mydomain.io 时,Chrome 中出现重定向循环错误。

我在 CloudFlare 上设置了免费的 SSL 证书,我不确定这是否会导致问题?当我访问 https://mydomain.io 时,它运行良好,并提供了绿色锁和 https。

【问题讨论】:

    标签: apache .htaccess mod-rewrite ssl https


    【解决方案1】:

    这段代码对我来说很好,但它是我 htaccess 中的第一个 RewriteRule。

    RewriteEngine on
    RewriteCond     %{SERVER_PORT} ^80$
    RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
    

    【讨论】:

    • 这个仍然给出一个错误,但下面的 cloudflare 答案除了 XP Chrome 以外的任何原因都有效。
    • @frosty 如果发生同样的错误(重定向循环),你必须在其他地方找到问题(不是 htaccess)
    【解决方案2】:

    cloudfare 上尝试此规则:

    RewriteEngine On
    
    RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,NE,R=302]
    

    【讨论】:

    • 这似乎适用于 Chrome Mac OSX 10.10,但在 XP Chrome(虚拟机)上它给了我一个错误:ERR_SSL_VERSION_OR_CIPHER_MISMATCH
    • 不确定是什么问题,但这似乎在大多数情况下都有效。
    猜你喜欢
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2015-10-09
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多