[英]Easy IIS 7.5 url rewrite rule (from non-www to www) gives redirect loop error in browser
这似乎应该是一个101级的问题,但我不能让它工作。
我只需要设置一个url重写规则,将mydomain.com重定向到www.mydomain.com。 而已。 但无论我怎么做,我的浏览器都会出现URL重定向错误。
以下是我尝试过的一些不同的规则定义,一个接一个。 据我所知,任何人都应该工作。 但没有人。 我会非常感激任何洞察力。
<rule name="non-www to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
<add input="{HTTP_HOST}" negate="true" pattern="^www.mydomain.com$" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="non-www to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\." negate="true" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
</rule>
<rule name="non-www to www" enabled="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
</rule>
在IIS中,它作为规范主机重定向内置。 请参阅以下内容,301将来自http://example.com的任何请求重定向到http://www.example.com
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.