【问题标题】:understanding IIS Proxy response header rewrite Rule理解 IIS Proxy 响应头重写规则
【发布时间】:2017-07-06 15:47:07
【问题描述】:

我们有一个 IIS 反向代理响应规则,它修改 Location HTTP 标头。我正在尝试解码逻辑并计划在 xslt 中编写相同的逻辑,有人可以解释以下逻辑。匹配模式是如何工作的,动作重写和值是如何工作的,这里的 R:1、R:2、R:3 是什么?

<rule name="Change Location Header" enabled="true">  
                <match serverVariable="RESPONSE_LOCATION" pattern="^http(s)?://([^/]+)/(.*)" />
                <conditions logicalGrouping="MatchAny" trackAllCaptures="true">
                    <add input="{RESPONSE_STATUS}" pattern="^301" />
                    <add input="{RESPONSE_STATUS}" pattern="^302" />
                </conditions>
                <action type="Rewrite" value="http{R:1}://{R:2}/{R:3}" />
            </rule>

【问题讨论】:

    标签: xslt iis url-rewriting reverse-proxy


    【解决方案1】:

    您的规则正在更改重定向响应的 HTTP 位置标头中的域

    工作匹配条件如何,什么是 R:1,R:2,R:3

    RESPONSE_LOCATION 变量具有完整的喜欢 url。例如:

    https://demo.cloudimg.io/s/width/300/sample.li/boat.jpg
    

    在这种情况下,使用正则表达式进行匹配操作后:^http(s)?://([^/]+)/(.*) 数学会是这样的:

    {R:0}   https://demo.cloudimg.io/s/width/300/sample.li/boat.jpg
    {R:1}   s
    {R:2}   demo.cloudimg.io
    {R:3}   s/width/300/sample.li/boat.jpg
    

    【讨论】:

    • 嗨,维克多,感谢您的回复,我真的很感激。我可以知道demo.cloudimg.io/s/width/300/sample.li/boat.jpg 的修改后的位置标头值是多少
    • 可以在 xslt 中使用 regex-replace 来实现同样的事情,如下所示 demo.cloudimg.io/s/width/300/sample.li/boat.jpg', ' ^http(s)?://([^/]+)/(.*)', 'g', 'http{R:1}://{R:2}/{R:3}') " />
    猜你喜欢
    • 2011-07-18
    • 2012-09-27
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    相关资源
    最近更新 更多