2011-07-27 38 views
0

我试图关闭HTTPS时有人打我的网站的根......IIS7 URL重写模块规则帮助

我想

https://www.domain.com/ 

重定向到

http://www.domain.com/ 

但我也想..

https://www.domain.com/secure.aspx 

或任何其他指定页面不重定向。

这是我到目前为止,但我不能得到它的工作。我尝试了上千种方法,并阅读了所有关于此的IIS文档和示例,但我无法想出这个神奇的公式。

<rule name="Redirect Root Only to Non HTTP" stopProcessing="true"> 
    <match url="\.com/$" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTPS}" pattern="on" /> 
    </conditions> 
    <action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Found" /> 
</rule> 

回答

0

你很接近..除了实际模式(只匹配URL路径部分而不是域名)。正确的模式是^$,这意味着空字符串将只与域根匹配匹配,例如https://www.domain.com/

完整的规则将是:

<rule name="Redirect Root to HTTP" stopProcessing="true"> 
    <match url="^$"/> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{HTTPS}" pattern="on"/> 
    </conditions> 
    <action type="Redirect" url="http://www.domain.com/" redirectType="Permanent"/> 
</rule> 
1

我想这就是你的答案:

<rule name="Redirect to HTTPS" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
    <add input="{URL}" pattern="^.*\.aspx$" ignoreCase="true" /> 
    <add input="{HTTPS}" pattern="^OFF$" /> 
    </conditions> 
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
</rule> 
<rule name="Redirect to HTTP" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions> 
    <add input="{URL}" pattern="^$" /> 
    <add input="{HTTPS}" pattern="^ON$" /> 
    </conditions> 
    <action type="Redirect" url="http://{HTTP_HOST}/" redirectType="Permanent" /> 
</rule>