2016-03-29 96 views
0

我試圖強制兩個http頁面https。當我做的登錄頁面,它完美的作品:RewriteRule第一條規則的作品,第二條規則不重定向到https

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^login\.htm$ https://www.sample.com/dev/login.htm [R=301,NC,L] 

然而,當我試圖添加第二頁,我得到這個服務器錯誤:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^login\.htm$ https://www.sample.com/dev/login.htm [R=301,NC,L] 
RewriteRule ^register\.htm$ https://www.sample.com/dev/register.htm [R=301,NC,L] 

顯然,出事了。所以我改成了簡單重定向第二頁,而不是重寫規則上:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^login\.htm$ https://www.sample.com/dev/login.htm [R=301,NC,L] 
Redirect ^register\.htm$ https://www.sample.com/dev/register.htm [R=301,NC,L] 

該網站又回來了,但第二頁沒有強制HTTPS的。我已經檢查了所有,它應該工作,但它不。感謝您的幫助。

回答

1

重寫條件僅適用於緊隨其後的規則。所以,你有兩個選擇:

選項1:重複每個規則的條件

RewriteCond %{HTTPS} off 
RewriteRule ^login.htm$ https://www.sample.com/dev/login.htm [R=301,NC,L] 

RewriteCond %{HTTPS} off 
RewriteRule ^register.htm$ https://www.sample.com/dev/register.htm [R=301,NC,L] 

選項2:兩個匹配的URI使用一個規則

RewriteCond %{HTTPS} off 
RewriteRule ^(login|register).htm$ https://www.sample.com/dev/$1.htm [R=301,NC,L]