2

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

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

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

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

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

我应该怎么办?

4

1 回答 1

0

这会将端口 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]
于 2012-06-29T01:17:23.993 回答