HTTP到HTTPS 301重定向代码不起作用,它说太多重定向 [英] HTTP to HTTPS 301 Redirection Code is Not Working, It says Too many redirects

查看:422
本文介绍了HTTP到HTTPS 301重定向代码不起作用,它说太多重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个网站上使用Bluehost。最近,我最近将我的网站从HTTP移到了HTTPS。
之后,我使用了可能不同的代码,包括以下代码,强制我的网站上的HTTPS。

I am using Bluehost for one of my websites. Recently, Recently, i have moved my site from HTTP to HTTPS . After that, I have used So may different code including the below code to force HTTPS all over my website.

# SSL Rewrite
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

使用此帖子后,当我在网上查看 redirect-checker 上的重定向时,我收到以下消息。

After using this post, when I check redirection on redirect-checker available on online, I get following messages.


但它不起作用。重定向太多。请尝试减少 http://www.example.com
重定向次数。您使用19重定向。
理想情况下,您不应在重定向链中使用超过3个重定向。
超过三次重定向会在您的
服务器上产生不必要的负载并降低速度,最终导致糟糕的用户体验。

But it is not working. Too many redirects. Please try to reduce your number of redirects for http://www.example.com. You use 19 Redirects. Ideally, you should not use more than 3 Redirects in a redirect chain. More than three redirections will produce unnecessary load on your server and reduce speed, which ends up in bad user experience.

如果您想从浏览器访问我的网站 ,我会收到警告:

And If you want to access my website from a browser, I get warning as such:


www.example.com页面无效。 www.example.com重定向你
太多次了。

The www.example.com page isn’t working. www.example.com redirected you too many times.

我认为一些重定向循环正在造成这样的问题。

I think some redirection loop was creating such problem.

然而,

我的网站状态现在:不使用htaccess上的任何代码

My web site Status Right Now: Without using any code on htaccess



  1. https // www.example.com工作得很好。返回200 OK。 200 OK2

  1. https//www.example.com is working just fine. returning 200 OK. 200 OK2

https // example.com现在301被重定向到https // www.example.com(所以,我觉得它也很好)

https//example.com is now 301 redirected to https//www.example.com (So, i think it is also just fine)


问题是:



  1. http // example.com现已301重定向到http // www.example.com

  2. HTTP // WWW。 example.com返回200 OK。


要解决问题3,我在下面的代码中包含了htaccess

To solve problem 3, I included Below code on my htaccess

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

之后我发现:


http // example.com现在是301重定向到https // www.example.com

http//example.com is now 301 redirected to https//www.example.com

所以问题解决了:

http//example.com
https//example.com
https//www.example.com

现在我只需要一些代码来重定向301:

Now I just need some code to redirect 301 only:


http // www.example.com https // www.example.com`

http//www.example.com TO https//www.example.com`

有人可以帮我吗?

如果我以有线的方式解释我的问题,我很抱歉......:D。问题是我不是这方面的专家。希望大家都明白。

And I am sorry if I explain my problem in a wired way... :D. The matter is I am not an expert guy on this. Hope you all will understand.

推荐答案

试试这个:

RewriteEngine On

# If not www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# rewrite to https and www
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]

# If not HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]

这篇关于HTTP到HTTPS 301重定向代码不起作用,它说太多重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆