2

May i ask how do i rewrite url from

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

to

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

the query string "animal_record_no" is optional.

Basically i just want to remove the "test" from the url and change the ip address.

This is what i have now, but it does not forward the query string:

                <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>

If i were to use redirect, i got a HTTP/1.1 301 Moved Permanently error

<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}" /> 

Thanks for the help.

0

1 Answer 1

3

Add URL Rewrite like below:

enter image description here

We don’t need to add rules for the query string, we just need to enable "Append query string", IIS will help us rewrite query string.

The configuration in web.config is as follows:

       <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>

If the two ULRs are not pointing to the same host, you also need to enable reverse proxy.

Feel free to let me know if the problem persists.

Sign up to request clarification or add additional context in comments.

1 Comment

many thanks Ding Peng. I have not tried this. Will get back should i need help. Let me mark it as an answer first :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.