【问题标题】:IIS redirect www to non www using httpsIIS 使用 https 将 www 重定向到非 www
【发布时间】:2021-12-03 14:12:53
【问题描述】:

我需要一些帮助来实现重定向。

我得到的结果如下:

http://example.com - https://example.com   : works
http://www.example.com - https://example.com   : works
https://www.example.com - https://example.com   : doesn't work

我的配置文件:

<rule name="RedirectWwwToNonWww" stopProcessing="false">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
    </conditions>
    <action type="Redirect" url="https://{C:2}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="true">
    <match url="(.*)" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

【问题讨论】:

标签: http redirect iis https


【解决方案1】:

你可以试试这个规则:

<rule name="Force non-WWW" enabled="true" stopProcessing="true">
  <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
    </conditions>
  <action type="Redirect" url="https://{C:2}/{R:1}" appendQueryString="true" />
</rule>
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
  <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
      <add input="{HTTPS}" pattern="off" />
    </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
</rule>

【讨论】:

  • 您好,感谢您回复我。不幸的是,同样的结果。我需要这个的原因是我的 ssl 证书仅支持 example.com(非 www)也许最简单的方法是通过支持两者的新证书?
  • 这条规则对我有用,你可以尝试使用失败的请求跟踪来查看错误信息。
猜你喜欢
  • 2019-12-13
  • 1970-01-01
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-22
  • 1970-01-01
相关资源
最近更新 更多