2012-04-19 45 views
0

我想要拿出一個單一的重寫規則,檢查url字符串,如果它包含一些字,重寫它的https版本。一個重寫規則能夠重寫多個網址到他們的https(mod_rewrite)

例如:需要爲所有這些情形之一的重新寫入規則]

$http://www.example.com/account/login to https://www.example.com/account/login 
$http://www.example.com/checkout to https://www.example.com/checkout 
$http://www/example.com/info/contact to https://www.example.com/info/contact 

這不工作,我不知道爲什麼

$RewriteCond %{HTTPS} off 
$RewriteCond %{REQUEST_URL} checkout|account 
$RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

回答

1

喜歡的東西:

RewriteCond %{HTTPS} off 
RewriteRule ^(account/.+|checkout|info/contact)$ https://www.example.com/$1 [R=301,L] 
+0

可能需要像'RewriteCond%{HTTPS} off'這樣的東西,所以你沒有得到一個無限循環? – 2012-04-19 18:47:37

+0

這將工作,但我必須重寫帳戶/所有內容到https不只是/登錄 – Aresn 2012-04-19 18:48:25

+0

是的,絕對,假設執行相同的重寫規則將被選爲https。回答更新 – 2012-04-19 18:49:51