使用查询字符串重写iis url

使用查询字符串重写iis url,iis,url-rewriting,Iis,Url Rewriting,我可以问一下如何从中重写url吗 "https://hello.com/test/api/zoo/v1/animal?animal_record_no=20900016431" 到 "https://145.123.2.12:5000/api/zoo/v1/animal?animal_record_no=20900016431" 查询字符串“animal_record_no”是可选的 基本上,我只想从url中删除“test”并更改ip地址 这是我现在拥有的,但它不转发查询字符串:

我可以问一下如何从中重写url吗

"https://hello.com/test/api/zoo/v1/animal?animal_record_no=20900016431"

"https://145.123.2.12:5000/api/zoo/v1/animal?animal_record_no=20900016431"

查询字符串“animal_record_no”是可选的

基本上,我只想从url中删除“test”并更改ip地址

这是我现在拥有的,但它不转发查询字符串:

                <rule name="ReverseProxyInboundRule3" stopProcessing="true">
                    <match url="^test/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/?$" />
                    <action type="Rewrite" url="http://145.123.2.12:5000/{R:1}/{R:2}/{R:3}/{R:4}" />
                    <conditions>
                    </conditions>
                </rule>

如果我使用重定向,我会得到一个HTTP/1.1错误

<rule name="ReverseProxyInboundRule3" enabled="true" stopProcessing="true">                     <match url=".*test/(.*)" />                        
<conditions>                         
<add input="{HTTP_HOST}" pattern="iex.odp.gov.sg" />                    
</conditions>                   
<action type="Redirect" url="http://145.123.2.12:5000/{R:1}" /> 


感谢您的帮助。

添加URL重写,如下所示:

我们不需要为查询字符串添加规则,只需启用“追加查询字符串”,IIS将帮助我们重写查询字符串。

web.config中的配置如下所示:

       <rewrite>
            <rules>
                <rule name="Test">
                    <match url="(.*)(test)/(api)/(zoo)/(v1)/(animal)" />
                    <action type="Rewrite" url="https://145.123.2.12:5000/{R:3}/{R:4}/{R:5}/{R:6}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>

如果两个ULR不指向同一主机,您还需要启用反向代理。


如果问题仍然存在,请随时通知我。

非常感谢丁鹏。我没有试过这个。如果我需要帮助,我会回来的。让我先把它标记为一个答案:)