开发者

IIS7 URL Rewrite module rule help

I'm trying to turn off HTTPS when someone hits the root of my site...

I want

https://www.domain.com/ 

to redir开发者_JS百科ect to

http://www.domain.com/

but I also want..

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

or any other named page not to redirect.

Here's what I have so far but I can't get it to work. I tried a thousand ways, and read all the IIS documentation and examples on this, but I can't come up with the magic formula.

<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> 


I think this is your answer:

<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>


You were close .. except the actual pattern (which matches URL path part only and not domain name). The proper pattern is ^$ which means empty string which will ONLY match domain root hit e.g. https://www.domain.com/.

The full rule will be:

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜