【问题标题】:Trouble getting redirects right using web.config for IIS使用 IIS 的 web.config 正确获取重定向时遇到问题
【发布时间】:2017-12-27 23:37:15
【问题描述】:

好的,这里有一个奇怪的重定向问题。我有 3 个域名,所以我们将它们称为以下名称

maindomain.com
aliasdomain.net
aliasdomain.org

我们在 Windows 2016 服务器上通过 IIS 使用 Let's Encrypt for https。

我们想要的是任何时候一个人在 3 个域中的任何一个中键入或 www 都重定向到域名 www.maindomain.com

由于我们加密证书没有创建 www。域别名的版本给我们带来了一些困难。这是我们正在使用的 web.config 规则,但它们不起作用。

<rule name="Redirect to WWW" enabled="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^www\." negate="true" />
    </conditions>
    <action type="Redirect" url="https://www.{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to HTTPS" enabled="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="OFF" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />
</rule>

所以这个结果如下 这有效 www.maindomain.com 工作并重定向到https://www.maindomain.com maindomain.com 工作并重定向到https://www.maindomain.com

这不起作用,奇怪的是显示标准 IIS 登录页面 aliasdomain.net 不起作用重定向到http://www.aliasdomain.net www.aliasdomain.net 不起作用并重定向到http://www.aliasdomain.net

这个完全不行 aliasdomain.org 不起作用重定向到https://www.aliasdomain.org www.aliasdomain.org 不起作用并重定向到https://www.aliasdomain.org

不知道如何让它做我们想要的。您会认为将任何版本的任何域名重定向到https://www.maindomain.com 并不难

感谢您的帮助。

【问题讨论】:

  • 修改rewriteRules.config后是否保存了web.config?
  • 是的,我保存了它。

标签: redirect iis web-config iis-10


【解决方案1】:

你的规则的问题是你在你的 重定向操作。此参数将从中获取传入主机名 请求。我认为这不是你想要的。 <action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false" />

请尝试以下规则。如果主机名不匹配,它会重定向 www.maindomain.com ,也强制执行 https

 <rule name="CanonicalHostNameRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^www\.maindomain\.com$" negate="true" />
                        <add input="{HTTPS}" pattern="off" />
                    </conditions>
                    <action type="Redirect" url="https://www.maindomain.com/{R:1}" />
                </rule>

【讨论】:

  • 实际上这是在我清除缓存后完成的。谢谢。
猜你喜欢
  • 1970-01-01
  • 2020-09-18
  • 1970-01-01
  • 2013-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-03
  • 1970-01-01
相关资源
最近更新 更多