【问题标题】:Redirect to https://www.example.com重定向到 https://www.example.com
【发布时间】:2017-10-26 14:20:30
【问题描述】:

目前我正在使用http://example.com,但我想将所有内容重定向到 https://www.example.com

我在这里阅读了几个主题并尝试了很多解决方案,但对我没有任何效果。

我最后一次尝试是这样的:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

当我使用此代码时,我可以看到: enter image description here

但它也给了我这个信息:

页面未正确重定向。 Firefox 检测到 服务器正在以某种方式重定向对该地址的请求 永远不会完成。

你能帮我解决这个问题吗?

【问题讨论】:

    标签: .htaccess http redirect web https


    【解决方案1】:

    用您的域替换示例并尝试

    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^example\.com [NC] 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    

    【讨论】:

      【解决方案2】:

      在我看来,您还试图强制使用 www。您可以在 .htaccess 中使用它来完成这两项工作:

      RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
      RewriteCond %{HTTPS} !=on
      RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
      

      将此规则放在您的 .htaccess 文件的顶部,并确保在测试之前清除缓存

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-27
        • 1970-01-01
        • 2015-09-25
        • 1970-01-01
        • 2019-11-11
        • 2015-12-06
        • 2021-11-13
        • 1970-01-01
        相关资源
        最近更新 更多