我有/安全页面,我需要将打开此页面的用户重定向到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]
但在安全页面上我得到循环转发。我该如何避免这个问题?
答案 0 :(得分:0)
您可以使用以下两条规则:
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]