2011-02-11 56 views
0

我想重定向所有HTTPS URL中輸入http重定向特定的URL(除了一個帳戶/付款):問題嘗試使用SSL

RewriteCond %{SERVER_PORT} =80 
RewriteCond %{REQUEST_URI} account/payment$ 
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

RewriteCond %{SERVER_PORT} =443 
RewriteCond %{REQUEST_URI} !account/payment$ 
RewriteRule (.*) http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule . - [L] 

RewriteRule . index.php [L] 

工作正常,但如果我要http://url/account/payment,它的重定向我http://url/index.php

謝謝

+0

我認爲`REQUEST_URI`需要`/`匹配:`/ account/payment $` – 2011-02-11 13:24:23

回答

0

L flag使已經重寫URL的再注入到重寫的過程:

但是,請記住,如果RewriteRule生成內部重定向(在每個目錄上下文中重寫時經常發生),則會重新注入請求並導致從第一個RewriteRule開始重複處理。

爲了避免要麼你的前兩個規則是這樣的重新注入URL應用,檢查request line代替:

RewriteCond %{SERVER_PORT} =80 
RewriteCond %{THE_REQUEST} ^GET\ /account/payment[?\ ] 
RewriteRule ^account/payment$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

RewriteCond %{SERVER_PORT} =443 
RewriteCond %{THE_REQUEST} !^GET\ /account/payment[?\ ] 
RewriteRule !^account/payment$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 
0

每次RewriteRule比賽,阿帕奇做一個內部重定向和重新評估所有針對新(重寫)路徑的重寫規則。

因此,當RewriteRule . index.php匹配時,REQUEST_URI更改爲index.php並且所有重寫規則將再次評估。

RewriteCond %{REQUEST_URI} !account/payment$index.php的計算結果爲true,並且評估下一個規則:RewriteRule (.*) http://% {SERVER_NAME}%{REQUEST_URI},它將(從外部)重定向到index.php。