.htaccess错误-ERR_TOO_MANY_REDIRECTS [英] .htaccess error - ERR_TOO_MANY_REDIRECTS

查看:258
本文介绍了.htaccess错误-ERR_TOO_MANY_REDIRECTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个.htaccess文件将http://重定向到https://
我也做了www.到根域重定向!
www.到根域有效!但是https://重定向不! 如果将RewriteCond %{HTTPS} on设置为RewriteCond %{HTTPS} offRewriteCond %{HTTPS} =!on,则会出现浏览器错误:

I have this .htaccess file to redirect http:// to https://
I also did www. to root domain redirection!
www. to root domain works! however https:// redirection doesn't! If I set RewriteCond %{HTTPS} on to RewriteCond %{HTTPS} off or RewriteCond %{HTTPS} =!on I get a browser error:

example.com页面无法正常工作

mysite.com将您重定向了太多次.

mysite.com redirected you too many times.

尝试清除您的cookie.

Try clearing your cookies.

ERR_TOO_MANY_REDIRECTS


我所做的一次编辑给了我500错误,但我将其恢复为以前的状态!我所做的只是更改:将RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}更改为RewriteRule(.*) https://%{HTTP_HOST}%{REQUEST_URI}RewriteRule (.*)https://%{HTTP_HOST}%{REQUEST_URI}


One edit I did gave me a 500 error but I reverted that back to how it was before! all I did was change: RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} to RewriteRule(.*) https://%{HTTP_HOST}%{REQUEST_URI} or RewriteRule (.*)https://%{HTTP_HOST}%{REQUEST_URI}

这是我的整个.htaccess文件!

<IfModule mod_rewrite.c>
 RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} on          [OR]
RewriteCond %{HTTP_HOST} ^www\.   [NC]
RewriteRule ^ https://antimalwareprogram.co%{REQUEST_URI}     [R=301,L,NE]
</IfModule>

推荐答案

RewriteCond %{HTTPS} on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

是的,这将创建一个重定向循环.逻辑是错误的.这表示...如果HTTPS处于打开"状态,则重定向到HTTPS.您应该检查HTTPS是否关闭"(或不开启",即!on).

Yes, this will create a redirect loop. The logic is wrong. What this says is... if HTTPS is "on" then redirect to HTTPS. You should be checking if HTTPS is "off" (or "not on", ie. !on).

(通过删除参数之间的空格,您可能会创建一个重写循环,因此会出现500错误.空格是Apache配置文件中的分隔符.)

(By removing the spaces between the arguments you likely created a rewrite loop, hence the 500 error. Spaces are delimiters in Apache config files.)

请尝试以下类似方法:

RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=302,L,NE]

这同时处理HTTPS和www规范重定向.您不需要第一条规则.您也不需要<IfModule>容器.

This handles both the HTTPS and www canonical redirects. You don't need the first rule. You don't need the <IfModule> container either.

仅在确定其可以正常工作时,才将302更改为301.

Change the 302 to 301 only when you are sure it's working OK.

在测试之前,请确保已清除浏览器缓存. 301被浏览器硬缓存.

Make sure you've cleared your browser cache before testing. 301s get cached hard by the browser.

更新:如果这仍然给您带来相同的错误(重定向循环),则SSL可能由前端代理而不是应用程序服务器管理.如果是这种情况,那么您将无法使用HTTPS服务器变量.请参阅以下相关问题:

UPDATE: If this still gives you the same error (a redirect loop) then it's possible that your SSL is managed by a front-end proxy, not your application server. If this is the case then you won't be able to use the HTTPS server variable. See these related questions:

  • http to https redirection through htaccess: incorrect redirection error
  • htaccess rewrite - too many redirects

在这种情况下,似乎需要使用ENV:HTTPS(环境变量)代替HTTPS(Apache服务器变量).但是请注意,这是非标准的/特定于服务器的,因为这意味着正在使用前端代理来管理SSL.

It seems that in this case, ENV:HTTPS (an environment variable) needed to be used in place of HTTPS (Apache server variable). Note, however, that this is non-standard / server specific, as it implies a front-end proxy is being used to manage the SSL.

这篇关于.htaccess错误-ERR_TOO_MANY_REDIRECTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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