2011-07-27 148 views
9

我在我的htaccess文件重寫從URLhtaccess的幫助,需要強制WWW,HTTPS和刪除的index.php

RewriteEngine on 
RewriteCond $1 !^(images|media|system|themes|_css|_js|favicon\.ico|robots\.txt|cert\.html|index\.php) [NC] 
RewriteRule ^(.*)$ /index.php/$1 [L] 

刪除的index.php除了這個,我想迫使對於任何沒有任何請求的請求,可以使用wwwhttps

因此,最終所有的網址應該是這樣的:https://www.example.com/whatever/something/;和搜索引擎優化的目的,如果URL中肯綮,它應該301重定向到它的正確的版本,例如:

http://example.com/about/ 
301 redirect to 
https://www.example.com/about/ 

很想一些幫助完成目標的,謝謝!

回答

23

力WWW:

RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] # include 's' here to force ssl in addition to www 

力SSL:

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 

刪除 「的index.php」:

RewriteCond %{THE_REQUEST} /index.php HTTP 
RewriteRule (.*)index.php$ /$1 [R=301,L] 
+1

謝謝,這似乎工作得很好至今。如果我在瀏覽器中點擊https://domain.com/,我會得到證書不可信的錯誤,因爲證書只適用於www。有沒有辦法解決這個問題? – mjr

+5

@mjr獲取同時包含'domain.com'和'www.domain.com'的證書或更昂貴的通配符證書(將覆蓋所有子域)。不幸的是,安全通道(SSL)必須在HTTPS的HTTP部分啓動之前首先建立。換句話說,重寫規則在連接完全建立之前不會被執行。 – LazyOne

+0

感謝您的提示。 – mjr