gpt4 book ai didi

.htaccess - HTTP 到 HTTPS 301 重定向代码不工作,它说重定向太多

转载 作者:太空宇宙 更新时间:2023-11-03 12:53:50 24 4
gpt4 key购买 nike

我正在为我的一个网站使用 Bluehost。最近,最近,我已将我的网站从 HTTP 移至 HTTPS。之后,我使用了 So may 不同的代码(包括以下代码)在我的网站上强制使用 HTTPS。

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

使用这篇文章后,当我在在线可用的 redirect-checker 上检查重定向时,我收到以下消息。

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.

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

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

我认为某些重定向循环造成了这样的问题。

但是,

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

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

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

问题是:

  1. http//example.com is now 301 redirected to http//www.example.com
  2. http//www. example.com is returning 200 OK.

为了解决问题 3,我在我的 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 is now 301 redirected to https//www.example.com

所以问题解决了:

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

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

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

有人可以帮我吗?

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

最佳答案

试试这个:

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]

关于.htaccess - HTTP 到 HTTPS 301 重定向代码不工作,它说重定向太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42532560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com