您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

URL 重写(自定义转发路径)URL rewrite (custom forwarding path)

Azure 前门支持 URL 重写,方法是配置一个可选的 自定义转发路径 ,以便在构造转发到后端的请求时使用。Azure Front Door supports URL rewrite by configuring an optional Custom Forwarding Path to use when constructing the request to forward to the backend. 默认情况下,如果未提供自定义转发路径,则前门会将传入 URL 路径复制到在转发的请求中使用的 URL。By default, if a custom forwarding path isn't provided, the Front Door will copy the incoming URL path to the URL used in the forwarded request. 转发请求中使用的主机标头与为选定后端配置的主机标头一样。The Host header used in the forwarded request is as configured for the selected backend. 阅读后端主机标头,了解它的作用以及配置方式。Read Backend Host Header to learn what it does and how you can configure it.

URL 重写的强大部分是,自定义转发路径会将与通配符路径匹配的传入路径的任何部分复制到转发路径 (这些路径段是以下示例中的 绿色 段) :The powerful part of URL rewrite is that the custom forwarding path will copy any part of the incoming path that matches to a wildcard path to the forwarded path (these path segments are the green segments in the example below):

Azure Front Door URL 重写

URL 重写示例URL rewrite example

请考虑使用配置了以下前端主机和路径组合的路由规则:Consider a routing rule with the following combination of frontend hosts and paths configured:

主机Hosts 路径Paths
www.contoso.comwww.contoso.com /*
/foo/foo
/foo/*/foo/*
/foo/bar/*/foo/bar/*

下表的第一列显示了传入请求的示例,第二列显示了“最确切”的匹配路由“路径”。The first column of the table below shows examples of incoming requests and the second column shows what would be the "most-specific" matching route 'Path'. 表中的第三个和第三列是配置的 自定义转发路径的示例。The third and ensuing columns of the table are examples of configured Custom Forwarding Paths.

例如,如果查看第二行,可发现其表示对于传入请求 www.contoso.com/sub,如果自定义转发路径为 /,则转发的路径将为 /subFor example, if we read across the second row, it's saying that for incoming request www.contoso.com/sub, if the custom forwarding path was /, then the forwarded path would be /sub. 如果自定义转发路径为 /fwd/,则转发的路径为 /fwd/subIf the custom forwarding path was /fwd/, then the forwarded path would be /fwd/sub. 其余列以此类推。And so forth, for the remaining columns. 下方路径中强调的部分表示通配符匹配的部分。The emphasized parts of the paths below represent the portions that are part of the wildcard match.

传入的请求Incoming request 最确切的匹配路径Most-specific match path / /fwd//fwd/ /foo//foo/ /foo/bar//foo/bar/
www . contoso.com/www.contoso.com/ /* / /fwd//fwd/ /foo//foo/ /foo/bar//foo/bar/
www . contoso.com/subwww.contoso.com/sub /* /该子/sub /fwd/sub/fwd/sub /foo/sub/foo/sub /foo/bar/sub/foo/bar/sub
www . contoso.com/a/b/cwww.contoso.com/a/b/c /* /a/b/c/a/b/c /fwd/a/b/c/fwd/a/b/c /foo/a/b/c/foo/a/b/c /foo/bar/a/b/c/foo/bar/a/b/c
www . contoso.com/foowww.contoso.com/foo /foo/foo / /fwd//fwd/ /foo//foo/ /foo/bar//foo/bar/
www . contoso.com/foo/www.contoso.com/foo/ /foo/*/foo/* / /fwd//fwd/ /foo//foo/ /foo/bar//foo/bar/
www . contoso.com/foo/barwww.contoso.com/foo/bar /foo/*/foo/* //bar /fwd/bar/fwd/bar /foo/bar/foo/bar /foo/bar/bar/foo/bar/bar

可选设置Optional settings

还可以为任何给定的路由规则设置指定其他可选设置:There are additional optional settings you can also specify for any given routing rule settings:

  • 缓存配置 -如果已禁用或未指定,则与此路由规则匹配的请求将不会尝试使用缓存的内容,而是始终从后端提取。Cache Configuration - If disabled or not specified, requests that match to this routing rule won't attempt to use cached content and instead will always fetch from the backend. 阅读关于使用 Front Door 缓存的详细信息。Read more about Caching with Front Door.

后续步骤Next steps