2011-08-21 67 views
0

我試圖優化我的重定向Apache的重定向規則優化

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^boycottplus\.org$ 
RewriteRule^https://boycottplus.org%{REQUEST_URI} [L,R=301] 

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

第1部分是重定向訪問.COM網站的.ORG網站用戶

第2部分是將用戶重定向是訪問不安全(http)到https

有沒有辦法將.com用戶重定向到安全的.org站點,並將.org站點上的http用戶重定向到https站點?兩者都保持{request_uri}完整?

回答

1

使用在一個規則或兩個條件同時應用邏輯,而不是默認和:

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^boycottplus\.org$ [OR] 
RewriteCond %{HTTPS} =off 
RewriteRule^https://boycottplus.org%{REQUEST_URI} [L,R=301] 
+0

感謝。我仍然無法弄清楚它爲什麼在chrome中工作,但在Firefox中重定向到index.php頁面 – Justin

+0

嘗試清除瀏覽器緩存並重新啓動 - Firefox仍然可以記住以前實驗中的舊重定向。 – LazyOne

+0

謝謝..得到了它的想法,必須將規則移動到.htaccess的頂部,因爲有一些規則在那裏爲乾淨的URL – Justin