【问题标题】:The page isn't redirecting properly error http - https auto redirect showing error in website页面未正确重定向错误 http - https 自动重定向在网站中显示错误
【发布时间】:2019-07-05 18:42:54
【问题描述】:

每当我输入以下 http - https 自动重定向代码时,我都会收到此错误“页面未正确重定向”

连接到“网站 URL”时出错。 此问题有时可能是由禁用或拒绝接受 cookie 引起的。”

htaccess 代码如下。

 # Rewrite engine code https redirect
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 # Rewrite engine code for www to non ww version of website
 RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
 RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]

【问题讨论】:

    标签: html .htaccess https


    【解决方案1】:

    您必须添加一个测试,因为此时您为每个请求运行第一条规则。
    并且仅在 https 之前不带 www 重定向。

    尝试:

    RewriteEngine on
    # http(s)://(www.)?domain   ->  https://domain
    # www -> https without www
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
    # http -> https
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
    

    【讨论】:

    • 嘿@croises,谢谢你的帮助,现在它就像蛋糕一样工作。欣赏!
    • 嘿@croises,虽然我无法找出我的错误,请你再多说明一下。提前致谢。
    • 如我所说,你必须在 (RewriteCond) 之前添加一个测试,因为你为每个请求运行第一条规则
    猜你喜欢
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多