2013-10-10 277 views
2

我有安全页面,并且我需要将打开此页面的用户重定向到https协议。但所有其他人只能使用http打开。我想用.htaccess来做到这一点.httacces从http重定向到https页面

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

您可以使用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] 
+0

我尝试使用此解决方案,但我得到的循环转发。 – user1958350

+0

刚刚编辑过,你现在可以试试。 – anubhava

+0

@ user1958350:有用吗? – anubhava

相关问题