【问题标题】:Redirect Azure Static Web App from naked domain to www将 Azure 静态 Web 应用程序从裸域重定向到 www
【发布时间】:2022-11-05 07:00:23
【问题描述】:

我已经设置了一个带有自定义域的 Azure 静态 Web 应用程序。 example.com 和www.example.com 均已正确设置并正常工作。

我现在想在 staticwebapp.config.json 中创建一些规则,这样所有进入https://example.com/* 的请求都会重定向到https://www.example.com/*。

有没有办法做到这一点?我知道我可以用 Front Door 或类似的东西来做,但我可以通过静态 Web 应用程序中的规则来做吗?

【问题讨论】:

    标签: azure azure-static-web-app azure-static-web-app-routing


    【解决方案1】:

    我的解决方案不是您所要求的,但您的问题几乎完全描述了我所需要的。所以我为我的需要留下了一个解决方案^^

    我主要想将主机重定向到主机,所以https://example.comhttps://www.example.com。我不一定需要路径。

    我最终为https://example.com 创建了第二个静态Web 应用程序,添加了一个虚拟index.html 和一个staticwebapp.config.json,内容如下:

    {
        "routes": [
            {
                "route": "/*",
                "redirect": "https://www.example.com",
                "statusCode": 301
            }
        ]
    }
    

    这会将https://example.com* 重定向到根https://www.example.com。我没有找到在单个静态 Web 应用程序中执行此操作的方法。

    但是,这并没有结束路径。所以https://example.com/path 也将被重定向到https://www.example.com

    【讨论】:

      猜你喜欢
      • 2015-01-07
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 2020-02-05
      • 2014-03-29
      • 1970-01-01
      • 2021-06-02
      相关资源
      最近更新 更多