【问题标题】:.htaccess this web page has a redirect loop htaccess.htaccess 这个网页有一个重定向循环 htaccess
【发布时间】:2012-06-30 13:33:14
【问题描述】:

我想将我所有的 http 流量重定向到我网站中的 https。

我的 .htaccess 文件中有以下代码

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

当我将此文件放在目录中时,我收到一条错误消息,提示“此网页具有重定向循环 htaccess”

我看不到导致任何重定向的任何其他文件。

我该怎么办?

【问题讨论】:

  • 它是否适用于这个 RewriteRule? RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1
  • 我复制了你的确切代码,它工作正常。您的.htaccess 文件中还有其他规则吗?
  • 你在更高的目录中有.htaccess文件吗?
  • rewriting http to https 上查看此内容,但建议您使用mod_alias 代替Redirect to https
  • 试试RewriteCond %{HTTPS} !=onRewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

标签: html security .htaccess


【解决方案1】:

这会将端口 80(标准 http)上的所有流量重定向到 https:

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

或者,相反 - 重定向不在端口 443 (https) 上的任何流量:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

你也可以试试:

RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

【讨论】:

  • 如果您查看 cmets,您会看到它可以正常重定向到 HTTPS,但仍然显示该错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-27
  • 2013-12-22
  • 2013-11-06
  • 2013-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多