将url转换为https时出现web.config问题



我看了很多关于这个和其他网站的建议,但没有找到任何能完全解决我问题的东西。我有一个网站的SSL证书只适用于www.site.co.uk,而不是site.co.uk。所以我需要一些东西来添加一个缺失的https://和www.。我尝试过的规则是:

<rule name="Redirect not www">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.teams-unpuzzled.co.uk$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.teams-unpuzzled.co.uk/{R:1}" />
</rule>
<rule name="not HTTPS or not www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="(HTTP_HOST}" matchType="Pattern" pattern="www." ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.teams-unpuzzled.co.uk/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

这适用于大多数输入,但https://teams-unpuzzled.co.uk没有添加www,浏览器将其标记为不安全,www.teams-unpuzzled.co.uk/online-team-building的输入丢失了最后一部分,显示为https://www.teams-unpuzzled.co.uk

30/07@Abraham我试过要求服务器名称指示,但它让情况变得更糟。我现在想出了这些规则,这些规则似乎很管用。(现在使用boxoff.co.uk进行操作,因为这不那么关键。(

<rule name="Not HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.boxoff.co.uk/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="HTTPS and not www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="on" />
<add input="(HTTP_HOST}" matchType="Pattern" pattern="^boxoff.co.uk$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.boxoff.co.uk/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

我们至少应该确保teams-unpuzzled.co.uk指向我们网站的IP,以便它可以应用URL规则。你添加了一个DNS条目来完成吗
一旦您确定其他域名(与www.teams-unpuzzled.co.uk不匹配(指向我们当前网站的IP,这些URL规则将生效。请参阅以下规则。

<rewrite>
<rules>
<rule name="MyRules" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
//we had to ensure that the other domain name points to the IP of our website so that the below condition will take effect.
<add input="{HTTP_HOST}" pattern="^www.teams-unpuzzled.co.uk$" negate="true" />
//Also, add an http binding to the website in order to match the below condition.
<add input="{https}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.teams-unpuzzled.co.uk{Request_URI}" appendQueryString="false" />
</rule>
</rules>
</rewrite>

最后,可以使用{Request_URI}变量来解决缺失的片段。

<action type="Redirect" url="https://www.teams-unpuzzled.co.uk{Request_URI}" appendQueryString="false" /> 

官方文件
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule
如果问题仍然存在,请随时通知我。

最新更新