以下非www 到 www.sitedomain.com 的重定向规则有效,但CDN域请求的免除条款( add input =& #34; {HTTP_HOST}" pattern =" cdnprefix.azureedge.net" negate =" true" )被忽略,cdn请求重定向到www .sitedomain.com。你能帮我修改重写部分来解决这个问题吗?
<rule name="Redirect non-www to www.sitedomain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<!-- domain is not canonical -->
<add input="{HTTP_HOST}" matchType="Pattern" ignoreCase="true" pattern="^sitedomain\.com$" />
<add input="{HTTP_HOST}" pattern="^www\.sitedomain\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="cdnprefix\.azureedge\.net" negate="true" />
</conditions>
<action type="Redirect" url="https://www.sitedomain.com{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
与有效的HTTP一起 - &gt; httpS重定向规则(拆分为简化CDN免除规则的解决方案),它看起来像这样:
<rule name="Redirect to https">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="Off" ignoreCase="true" />
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Redirect non-www to www.sitedomain.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<!-- domain is not canonical -->
<add input="{HTTP_HOST}" matchType="Pattern" ignoreCase="true" pattern="^sitedomain\.com$" />
<add input="{HTTP_HOST}" pattern="^www\.sitedomain\.com$" negate="true" />
<add input="{HTTP_HOST}" pattern="cdnprefix\.azureedge\.net" negate="true" />
</conditions>
<action type="Redirect" url="https://www.sitedomain.com{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
答案 0 :(得分:1)
对于规范域,您只需要此规则
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www.\sitedomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.sitedomain.com/{R:1}" />
</rule>
然后您可以为CDN添加下一部分
<add input="{HTTP_HOST}" pattern="cdnprefix\.azureedge\.net" negate="true" />
希望这有效!