2012-01-18 101 views
0

我有幾個域具有相同的子域,可能安全或不安全。我需要重定向每個來自重定向 .somesite.com的請求,以重定向到安全站點。我需要原始網址,域名,以及網站是否被要求爲安全或不安全。Apache將安全重定向到不安全的某些子域名

http://redirect.site1.com/page?id=1

重定向到

https://process.site4.com/page?id=3&domain=a.site1.com &安全=

and

https://redirect.site2.com/page?id=2

重定向到

https://process.site4.com/page?id=3&domain=a.site2.com &安全=

http://redirect.site3.com/page?id=3

重定向到

https://process.site4.com/page?id=3&domain=a.site3.com &安全=

http://www.site3.com/page?i d = 3

仍然是

http://www.site3.com/page?id=3

回答

1

我假設你想要的ID查詢字符串的重定向匹配嗎?

你的文檔根試試這個在您的.htaccess文件(或在您的服務器/虛擬主機配置,改變^page$正則表達式^/page$):

RewriteEngine On 

# check if secure= is already set, and set it either to 1 or 0 
RewriteCond %{QUERY_STRING} !secure= 
RewriteCond %{HTTPS} on 
RewriteRule ^page$ /page?%{QUERY_STRING}&secure=1 [L] 

RewriteCond %{QUERY_STRING} !secure= 
RewriteCond %{HTTPS} off 
RewriteRule ^page$ /page?%{QUERY_STRING}&secure=0 [L] 

# check if the host starts with a "redirect." and match against the "/page" URI 
RewriteCond %{HTTP_HOST} ^redirect\.(.+)$ [NC] 
RewriteRule ^page$ https://process.site4.com/page?domain=a.%1 [QSA,R,L] 

的QSA在最後的規則將確保「安全=',並將原始的'id ='查詢字符串參數粘貼到URL上。

+0

如何將規則應用於以流程子域開頭的那些網站,但這看起來像我所需要的。 – Davin 2012-01-18 19:41:22