0

我的网站使用外部身份验证服务,该服务将用户引导离开所需的页面,执行登录,然后重定向回来。

问题是当用户从 https 页面重定向时,身份验证服务(我无法修改)愚蠢地重定向回 http://,并在 URL 的末尾附加了 :443,这只会从 Apache 引发错误。

我已经有一个 htaccess 指令来确保用户始终在 https 上查看当前页面:

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

我正在寻找的是一个重写规则,它将检测以 http 开头并以:443 结尾的 URL,然后将其重定向到 https:// 而不附加端口。

我试过这个:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

但这似乎不起作用。

4

1 回答 1

0

Replace your .htaccess code with this code:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This rule will redirect all http traffic to https irrespective of any port being used with http requests.

于 2013-07-29T13:37:41.320 回答