2013-10-10 262 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

相關問題