【问题标题】:How to add rewrite rule to Azure web.config so that certain requests are not redirected?如何将重写规则添加到 Azure web.config,以便某些请求不会被重定向?
【发布时间】:2021-04-14 18:36:34
【问题描述】:

如何添加 URL 重写规则,以便来自用户代理的请求 - ReadyForRequest/1.0+(HealthCheck)HealthCheck/1.0 不会被重定向?我需要这个,以便 Azure 应用服务运行状况检查能够工作。

我找到了many SO posts about redirecting urls,但我找不到阻止某些请求重定向的 SO 帖子。

这篇文章是为我的previous post添加答案,但我只想关注真正的问题,因为我之前的帖子似乎关注了错误的话题。

感谢您的帮助

【问题讨论】:

  • 如果我的解决方案对您有启发或帮助,请将我的答案标记为accepted,谢谢~

标签: azure redirect web-config url-rewrite-module


【解决方案1】:

您可以在项目中添加web.config。它对我有用。

方法二

Startup.cs

public void Configure(IApplicationBuilder app)
{
    app.UseRouting();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapHealthChecks("/health");

        endpoints.MapGet("/{**path}", async context =>
        {
            await context.Response.WriteAsync(
                "Navigate to /health to see the health status.");
        });
    });
}

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true"/>
    <httpCompression>
      <staticTypes>
        <add mimeType="image/svg+xml" enabled="true"/>
      </staticTypes>
    </httpCompression>
    <rewrite>
        <rules>
            <rule name="Root Hit Redirect" stopProcessing="true">
                <match url="^$" />
                <action type="Redirect" url="/health" />
            </rule>
        </rules>
    </rewrite>
  </system.webServer>
</configuration>

【讨论】:

  • 谢谢,但我使用 Azure 应用服务、WordPress 和 PHP,所以我不能使用 Startup.cs,我也不能在你的健康检查中使用 web.config。
  • @Dika 你在这篇文章中添加了 web.config 标签。 ^-^
  • @Dika 你有这个网站的 .htaccess 文件吗?
猜你喜欢
  • 2014-11-04
  • 2014-11-14
  • 1970-01-01
  • 2017-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-09
  • 1970-01-01
相关资源
最近更新 更多