简体   繁体   English

重写应用程序网关规则 azure

[英]Rewrite rule on application gateway azure

i would like to implement a rewrite rule on my Application Gateway v2 or other way if exist on Azure.如果 Azure 上存在,我想在我的应用程序网关 v2 或其他方式上实施重写规则。

On application gateway i setup 2 path based rule for our main site that i call mywebsite.it deployed to webapp1:在应用程序网关上,我为我们的主站点设置了 2 个基于路径的规则,我称之为 mywebsite.it 部署到 webapp1:

1- if i reach mywebsite.it/function* it redirect traffic correctly to webapp2; 1- 如果我到达 mywebsite.it/function*,它会将流量正确重定向到 webapp2;

2- if i reach from mywebsite.it/myapplication*, for example mywebsite.it/myapplication/images/xyz the application start with mywebsite.it/function*. 2- 如果我从 mywebsite.it/myapplication* 到达,例如 mywebsite.it/myapplication/images/xyz,应用程序以 mywebsite.it/function* 开头。 This rule point also to webapp2;此规则也指向 webapp2;

I would like to do this for scenario 2. From mywebsite.it/myapplication/images/xyz, apply a rewrite that change only /myapplication/, for example mywebsite.it/function/images/xyz.我想为场景 2 执行此操作。从 mywebsite.it/myapplication/images/xyz,应用仅更改 /myapplication/ 的重写,例如 mywebsite.it/function/images/xyz。 I need to mantain the path after function/* in rewrite operation(it is not static and change every time a user make a request when they pass from mywebsite.it/myapplication* )我需要在重写操作中保留 function/* 之后的路径(它不是 static 并且每次用户从 mywebsite.it/myapplication* 发出请求时都会更改)

I tried to configure the rewrite but it didn't work:我尝试配置重写,但没有成功:

在此处输入图像描述

在此处输入图像描述

I can't try evaluate path map, becouse in our http setting applied to path base rules(is the same becouse web app is the same), override backend path is enabled with /.我无法尝试评估路径 map,因为在我们应用于路径基本规则的 http 设置中(是相同的,因为 web 应用程序是相同的),覆盖后端路径使用 / 启用。 Without it application didn't work.没有它,应用程序将无法工作。

Any help is really appreciated非常感谢任何帮助

Would suggest you to please set the correct value for “Pattern to match” and “URL path value” and create the require object for HTTP header rewrite as it has stated according to the below Microsoft document.建议您为“要匹配的模式”和“URL 路径值”设置正确的值,并根据下面的 Microsoft 文档创建 rewrite object for HTTP header。 As it seems you have set wrong value for “Pattern to match” and “URL path value”.看起来您为“要匹配的模式”和“URL 路径值”设置了错误的值。

Refer this: https://learn.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers-portal参考这个: https://learn.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers-portal

The pattern to match is a regular expression.要匹配的模式是正则表达式。 In regular expressions, the forward slash ("/") is a reserved character so it must be escaped with a backslash (""), so it should look like ("/").在正则表达式中,正斜杠 ("/") 是保留字符,因此必须使用反斜杠 ("") 进行转义,因此它应该类似于 ("/")。 Use regex101.com to test your regular expression and ensure that you get a match when you expect it and no match when you do not expect it.使用 regex101.com 来测试您的正则表达式,并确保在您期望的时候得到匹配,而在您不期望的时候没有匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM