使用iis url rewrite将一个域重定向到另一个域时,如何修复https警告?

问题描述 投票:0回答:1

我有两个域,一个缩短,用于发送带有查询字符串的文本消息,因为常规域太长。目前,不同IP地址上的网页将短域重定向到长域,如果它具有正确的查询字符串,则重定向到特定页面,如果不具有,则重定向到主页。我正在迁移到Azure,我将只有一个IP地址。所以我认为IIS URL Rewrite能够处理这个任务。长域是仅限HTTPS的站点,并且有一个HTTPS规则。短域不是;链接始终只是HTTP。我在HTTPS规则之前设置了URL Rewrite来执行重定向,并为两个规则设置了stopProcessing =“true”。但是当我访问http://mytxt.net时,我收到一个浏览器警告SSL证书无效。

服务器是Windows Server 2016 IIS 10.我专门搜索了Google和Stackoverflow,但没有发现任何与我的问题相符的内容。下面是代码。

        <rule name="Txt QS Redirect" stopProcessing="true">
          <match url="^(www\.)?mytxt\.net"/>
          <conditions>
            <add input="{QUERY_STRING}" pattern="^MyQS"/>
          </conditions>
          <action type="Redirect" url="https://www.myfullsite.net/respond.aspx" appendQueryString="true" redirectType="Temporary"/>
        </rule>
        <rule name="Txt No QS Redirect" stopProcessing="true">
          <match url="^(www\.)?mytxt\.net"/>
          <conditions trackAllCaptures="false">
            <add input="{QUERY_STRING}" pattern="^MyQS" negate="true"/>
          </conditions>
          <action type="Redirect" url="https://www.myfullsite.net/" redirectType="Permanent"/>
        </rule>
        <rule name="HTTPS Redirect">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
        </rule>

不应该首先发生重定向,然后协议更改为HTTPS?或者浏览器是否首先检查SSL,当IIS说它已启用时,在客户端上进行协议更改?

iis https url-rewriting cross-domain
1个回答
0
投票

我解决了我的问题。这是问题的match url=正则表达式。也许一些IIS URL Rewrite guru可以告诉我们原因,因为我仍然不理解它。我用Failed Request Tracing发现它不匹配。此方法对于解决URL重写问题非常有用!我将它更改为match url=".*"并将原始正则表达式移至条件状态。这是工作代码。

<rule name="Txt QS Redirect" stopProcessing="true">
  <match url=".*"/>
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^(www\.)?mytxt\.net"/>
    <add input="{QUERY_STRING}" pattern="^MyQS"/>
  </conditions>
  <action type="Redirect" url="https://www.myfullsite.net/respond.aspx" appendQueryString="true" redirectType="Temporary"/>
</rule>
<rule name="Txt No QS Redirect" stopProcessing="true">
  <match url=".*"/>
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^(www\.)?mytxt\.net"/>
    <add input="{QUERY_STRING}" pattern="^MyQS" negate="true"/>
  </conditions>
  <action type="Redirect" url="https://www.myfullsite.net/" redirectType="Permanent"/>
</rule>

带有或不带www.的URL,以正确的查询字符串开头,被重定向到处理这些请求的页面;没有正确的查询字符串,它们将被重定向到站点的主页。

© www.soinside.com 2019 - 2024. All rights reserved.