[英]IIS7 URL Rewrite module rule help
I'm trying to turn off HTTPS when someone hits the root of my site... 当有人点击我网站的根目录时,我正在尝试关闭HTTPS。
I want 我想要
https://www.domain.com/
to redirect 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.
我尝试了一千种方法,并阅读了所有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>
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). 除了实际模式(仅与URL路径部分匹配,与域名不匹配)之外,您很接近.. The proper pattern is
^$
which means empty string which will ONLY match domain root hit eg https://www.domain.com/
. 正确的模式是
^$
,这意味着空字符串将仅匹配域根目录匹配,例如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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.