【问题标题】:Azure redirect non-www to wwwAzure 将非 www 重定向到 www
【发布时间】:2019-12-13 15:22:24
【问题描述】:

我对 Azure 重定向有疑问。

我已经搜索了其他主题,但不是我的问题。

我为此配置了 ASP.NET Core 2.2 项目和 Azure。我也有指向 Azure 的域。 我已将 www.example.com 格式的域添加到 azure,它也适用于 https。

example.com 格式出现问题

我想将 example.com 格式重定向到 www.example.com 网址

我设法用这个来完成这项工作,但时间很短。 我使用这个 web.config 进行重定向

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <rewrite>
      <rules>
        <rule name="CanonicalHostNameRule" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^example.com$" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/{R:0}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

有些奇怪的是 Google Chrome 和 Opera 重定向到 www 域,而不是 Edge 和 Firefox。 然后当我清除缓存时,它不会重定向。

似乎 Azure 喜欢重写一些东西。

感谢您的帮助!!

【问题讨论】:

  • 您检查过那些浏览器中的 F12 工具,是否收到 302 重定向?
  • 在 Edge 中,按 F12 查看浏览器控制台,然后按 Network 查看流量。将其与 chrome 中的相同内容进行比较。有什么不同吗?
  • 我没有收到任何 302 代码。问题也是为什么它在清除缓存后不起作用?!

标签: asp.net azure


【解决方案1】:

除了 web.config 文件更改之外,请确保 Azure 网站实例在 Hostname bindings 区域内包含正确的域绑定。

<rule name="Redirect to www">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^example.com$" negate="true" />
  </conditions>
  <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent"/>
</rule>

【讨论】:

    猜你喜欢
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2021-08-03
    • 2011-11-05
    • 2011-12-01
    相关资源
    最近更新 更多