2012-05-25 38 views
4

目前,在我的生產服務器上,我有如下的入站規則集,它可以滿足我所有的要求。在IIS中添加入站規則[UrlRewite]

入站規則如下。

Match URL section 
Requested URL: Matches the Pattern 
Using: Regular Expression 
Pattern: (.*) 
Ignore Case: checked. 

Conditions section 
Logical grouping: Match All. 
Input: {HTTPS} 
Type: Matches the Pattern 
Pattern: ^OFF$ 
Track capture groups across conditions: unchecked. 

Action section: 
Action type: Redirect 
Redirect URL: https://www.domainname.com/{R:0} 
Append query string: checked. 
Redirect Type: Permanent (301). 

我的要求是: 當用戶鍵入

https://beta.domain.com it should redirect to https://www.domain.com. 

如果用戶類型

http://beta.domain.com it should redirect to https://www.domain.com. 

如果用戶鍵入

http://www.domain.com it should redirect to https://www.domain.com 

如果用戶鍵入

http://domain.com it should redirect to https://www.domain.com 

在此先感謝。 任何幫助,將不勝感激。

在此先感謝。

回答

3

這不正是條件所假設的嗎?它會檢查HTTPS是否關閉,然後纔會發生重定向。如果HTTPS處於開啓狀態,則不會重定向,否則最終會導致無限重定向。

如果您始終希望主機名爲www.domainname.com您應該將其添加爲附加條件。例如: -

<rule name="Force HTTPS and host name: www.domainname.com" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAny"> 
     <add input="{HTTPS}" negate="true" pattern="^ON$" /> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.domainname\.com$" /> 
    </conditions> 
    <action type="Redirect" url="https://www.domainname.com/{R:0}" appendQueryString="true" redirectType="Permanent" /> 
</rule> 

如果任HTTPSONHTTP_HOSTwww.domainname.com會重定向。只有兩者都是真的,它纔會重定向。

+0

感謝Marco,我加了你的幫助!!!但這並不能滿足我的要求。請在我的主要問題中檢查我的要求。我已經更新了「需求」部分,更加清晰。 在此先感謝。 – shakti

+0

我認爲它滿足您的所有要求,但這是由於HTTPS的本質。如果您的SSL證書是「* .domainname.com」的通配符證書,或者它是「www.domainname.com」和「beta.domainname.com」的多域證書,則您的第一項要求才可用。如果您的證書僅對'www.domainname.com'有效,則當您打開「https:// beta.domainname.com」時,它會導致瀏覽器顯示安全警告。沒有什麼是你或IIS可以做的。 –