2010-09-07 35 views
0

我用下面的國防部重寫,以確保不僅規範的URL,而且該網站使用HTTPS顯示:ModRewrite使用HTTPS

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
// It think the problem must be here --^ 

RewriteCond %{HTTP_HOST} ^rto12\.ca$ [NC] 
RewriteRule ^(.*)$ https://www.rto12.ca/$1 [R=301,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php? 
RewriteRule ^index\.php?$ https://www.rto12.ca/ [R=301,L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html? 
RewriteRule ^index\.html?$ https://www.rto12.ca/ [R=301,L] 

我的問題是當你試圖去這裏:rto12.ca。 ..瀏覽器帶你到這裏:'https://www.rto12.ca/https://rto12.ca/'

這是造成這種情況的第一個條件/規則。任何建議,將不勝感激。

+0

你在使用強制的HTTPS?我沒有看到在這裏檢查的規則。 – 2010-09-07 14:59:02

+0

噢好點添,也許我的問題在於: RewriteCond%{HTTPS} off RewriteRule(。*)https://%{HTTP_HOST}%{REQUEST_URI} – jay 2010-09-07 15:05:46

回答

3

這條規則:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

...只會改寫請求https://rto12.ca/REQUEST_URI,然後將其傳遞給下一個規則(輸入下一個規則,你追加到的結束要求,將是https://rto12.ca/REQUEST_URI)。然而,它才能正常工作,你需要它立即重定向:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

很可能可以將所有規則合併成至多一個單一的重定向,所以讓我玩的有點和我」我會看到我能想出什麼,然後我會更新答案。不過,添加標誌應該可以解決您的問題。

編輯:我覺得這應該採取一切一氣呵成:

RewriteEngine On 

RewriteCond %{HTTPS}  =off [OR] 
RewriteCond %{HTTP_HOST} !^www\. [OR] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html|php) 
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)$ 
RewriteRule ^(index\.(html|php))|(.*)$ https://www.%2/$3 [R=301,L] 
+0

這絕對是Tim做的,謝謝!如果你想出一個單一的重定向來做我在這裏做的事情,我很樂意看到它。再次感謝。 – jay 2010-09-07 15:21:16

+0

@jeerose - 很酷,很高興它的工作。我已經用合併重定向塊更新了答案,看看是否照顧你想要的一切。 – 2010-09-07 15:28:19

+0

確實如此。蒂姆,非常感謝你的時間。 – jay 2010-09-07 15:36:04