2

我有 /secure 页面,我需要将打开此页面的用户重定向到 https 协议。但所有其他人都应该只用http打开。我想用 .htaccess 做到这一点

RewriteEngine on
RewriteRule ^secure(.+?) https://site.com/secure$1 [L,R=301]
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

但是在安全页面上,我得到了循环转发。我怎样才能避免这个问题?

4

1 回答 1

0

您可以使用 2 条这样的规则:

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

RewriteCond %{HTTPS} on
RewriteRule !^secure http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
于 2013-10-10T10:45:15.490 回答