我试图设置重写规则,但似乎没有正确的工作。 我的www.domain.org仍然在www。 我在这里错过了什么?
我从domain.orgredirect到HTTPS正常工作。
<rewrite> <rules> <rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^www\.tdccf\.org$" /> </conditions> <action type="Redirect" url="https://tdccf.org/{R:0}" /> </rule> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite>
谢谢!
您有指定的{HTTPS}input,而不是{HTTP_HOST} 。 {HTTPS}input包含on或off的文字值on它们永远不会匹配正则expression式^www\.tdccf\.org$ 。 另一方面, {HTTP_HOST}包含请求的主机部分。
<rewrite> <rules> <rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^www\.tdccf\.org$" /> </conditions> <action type="Redirect" url="https://tdccf.org/{R:0}" /> </rule> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite>
有关匹配语法的完整信息,请参阅MSDN文档 。