应用程序网关重定向概述Application Gateway redirect overview

可以使用应用程序网关来重定向流量。You can use application gateway to redirect traffic. 它有一种泛型重定向机制,用于将一个侦听器上接收到的流量重定向到另一个侦听器或外部站点。It has a generic redirection mechanism which allows for redirecting traffic received at one listener to another listener or to an external site. 这样可以简化应用程序配置、优化资源使用情况,并支持全局重定向和基于路径的重定向等新的重定向方案。This simplifies application configuration, optimizes the resource usage, and supports new redirection scenarios including global and path-based redirection.

为确保应用程序及其用户之间的所有通信都通过加密路径进行,适用于许多 Web 应用的常见重定向方案是支持 HTTP 到 HTTPS 自动重定向。A common redirection scenario for many web applications is to support automatic HTTP to HTTPS redirection to ensure all communication between application and its users occurs over an encrypted path. 过去用户曾使用创建专用的后端池等技术,其唯一目的在于将通过 HTTP 接收的请求重定向到 HTTPS。In the past, customers have used techniques such as creating a dedicated backend pool whose sole purpose is to redirect requests it receives on HTTP to HTTPS. 由于应用程序网关提供重定向支持,因此你可以很容易地完成此操作,只需向路由规则添加一个新的重定向配置,然后将使用 HTTPS 协议的另一个侦听器指定为目标侦听器即可。With redirection support in Application Gateway, you can accomplish this simply by adding a new redirect configuration to a routing rule, and specifying another listener with HTTPS protocol as the target listener.

支持以下类型的重定向:The following types of redirection are supported:

  • 301 永久性重定向301 Permanent Redirect
  • 302 已找到302 Found
  • 303 参见其他303 See Other
  • 307 临时重定向307 Temporary Redirect

应用程序网关重定向支持具有以下功能:Application Gateway redirection support offers the following capabilities:

  • 全局重定向Global redirection

    在网关上从一个侦听器重定向到另一个侦听器。Redirects from one listener to another listener on the gateway. 这样可实现站点上的 HTTP 到 HTTPS 重定向。This enables HTTP to HTTPS redirection on a site.

  • 基于路径的重定向Path-based redirection

    这种类型的重定向只能在特定站点区域中进行 HTTP 到 HTTPS 重定向,例如 /cart/* 表示的购物车区域。This type of redirection enables HTTP to HTTPS redirection only on a specific site area, for example a shopping cart area denoted by /cart/*.

  • 重定向到外部站点Redirect to external site

重定向

进行此更改后,客户需要创建新的重定向配置对象,以指定重定向需要指向的目标侦听器或外部站点。With this change, customers need to create a new redirect configuration object, which specifies the target listener or external site to which redirection is desired. 配置元素还支持一些选项,通过这些选项可以将 URI 路径和查询字符串追加到重定向的 URL。The configuration element also supports options to enable appending the URI path and query string to the redirected URL. 也可选择重定向的类型。You can also choose the type of redirection. 创建此重定向配置后,会通过新规则将其附加到源侦听器。Once created, this redirect configuration is attached to the source listener via a new rule. 使用基本规则时,重定向配置与源侦听器相关联,并且是全局重定向。When using a basic rule, the redirect configuration is associated with a source listener and is a global redirect. 使用基于路径的规则时,将在 URL 路径映射中定义重定向配置。When a path-based rule is used, the redirect configuration is defined on the URL path map. 因此,它仅适用于站点的特定路径区域。So it only applies to the specific path area of a site.

后续步骤Next steps

在应用程序网关上配置 URL 重定向Configure URL redirection on an application gateway