[英]IIS7 URL Rewrite module rule help
当有人点击我网站的根目录时,我正在尝试关闭HTTPS。
我想要
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>
我认为这是您的答案:
<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>
除了实际模式(仅与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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.