Fra*_*ein 5 iis https seo redirect
我需要避免在创建两个 IIS URL 重写规则后出现的双重重定向:
1)将www重定向到非www。
2) 将 HTTP 重定向到 HTTPS。
这是我的代码:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="CanonicalHostNameRule1" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^mydomain\.com$" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="https://ABC/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
(ABC 是 mydomain.com 名称,但我必须更改它才能发布问题)
问题是,如果我转到 www,它会执行两次重定向,一次从 www 到非 www,第二次从 http 到 https。
我也尝试过只使用一条规则来满足这两种条件,但结果并没有更好。
有没有办法只进行一次重定向?
这是我使用的最终配置:
<rewrite>
<rules>
<rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://yourdomainname.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
这只是重定向到非 www 和 https url 的一条规则。
归档时间: |
|
查看次数: |
4290 次 |
最近记录: |