重写URL重定向

时间:2019-11-04 22:19:04

标签: redirect iis http-redirect

我正在尝试从该地址重写URL:

https://merchant.test-01.mysite.co/payment-gateway/vend?amount=69.90&register_id=12&currency=NZD

到此地址:

https://mysite.co/nz/test-01/merchant/payment-gateway/vend?amount=69.90&register_id=12&currency=NZD

我尝试:

<rule name="test01Generic" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(\S+?).test-01.mysite.co$" />
    </conditions>
    <action type="Redirect" url="https://mysite.co/nz/test-01/{C:1}" redirectType="Found" />
</rule>

结果如下:

https://mysite.co/nz/test-01/merchant?amount=69.90&register_id=12&currency=NZD

缺少payment-gateway/vend的地方

还有这个

<rule name="test01Generic" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(\S+?).test-01.mysite.co$" />
    </conditions>
    <action type="Redirect" url="https://mysite.co/nz/test-01/{C:1}{REQUEST_URI}" redirectType="Found" />
</rule>

结果如下:

https://mysite.co/nz/test-01/merchant/payment-gateway/vend?amount=69.90&register_id=12&currency=NZD&amount=69.90&register_id=12&currency=NZD

查询参数加倍。

关于我想念什么的任何想法吗?

2 个答案:

答案 0 :(得分:0)

请将{REQUEST_URI}修改为{URL},并将appendQueryStrin保留为true,则可以。

 <rule name="test0Generic" stopProcessing="true">
    <match url=".*" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^(\S+?).test-01.mysite.co$" />
    </conditions>
    <action type="Redirect" url="https://mysite.co/nz/test-01/{C:1}{URL}" appendQueryString="true" redirectType="Found" />
</rule>

enter image description here

答案 1 :(得分:0)

我能够解决这个问题,我不得不将{REQUEST_URI}更改为{PATH_INFO}

<rule name="test01Generic" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(\S+?).test-01.mysite.co$" />
    </conditions>
    <action type="Redirect" url="https://mysite.co/nz/test-01/{C:1}{PATH_INFO}" redirectType="Found" />
</rule>

现在,当调用下面的地址时:

https://merchant.test-01.mysite.co/payment-gateway/vend?amount=69.90&register_id=12&currency=NZD

我要重定向到此地址:

https://mysite.co/nz/test-01/merchant/payment-gateway/vend?amount=69.90&register_id=12&currency=NZD