页面未正确重定向错误http-https自动重定向显示网站中的错误

时间:2019-02-12 07:15:40

标签: html .htaccess https

每当我输入以下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]

1 个答案:

答案 0 :(得分:0)

您必须添加一个测试,因为目前您为每个请求运行了第一个规则。
并仅在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]
相关问题