Rewriting route parameter [Answered]RSS

4 replies

Last post Mar 27, 2020 01:36 AM by Jalpa Panchal

  • Rewriting route parameter

    Mar 25, 2020 10:41 AM|ct1|LINK

    Apologies if this has been asked before, I have searched to no avail.

    I have a situation where there is a route parameter after the last slash I need to rewrite.

    I need to rewrite the url

    https://www.mysite.com/gw/Gateway/v1/DocumentDownload/3?forView=12

    to be as below, with the 3 and the forView moving into parameters.

    https://www.myothersite.com/cptond/api/getfile?id=3&forView=12

    If anyone could assist I would be grateful.

  • Re: Rewriting route parameter

    Mar 26, 2020 03:16 AM|Jalpa Panchal|LINK

    Hi,

    You could try below rule:

    <rule name="rule1" stopProcessing="true">
                        <match url="(.*)/(.*)/(.*)/(.*)/(.*)$" />
                        <conditions>
                            <add input="{QUERY_STRING}" pattern="(.*)" />
                        </conditions>
                        <action type="Redirect" url="https://www.myothersite.com/cptond/api/getfile?id={R:5}&amp;{C:1}" appendQueryString="false" />
                    </rule>

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: Rewriting route parameter

    Mar 26, 2020 11:38 PM|ct1|LINK

    Hi Jalpa - thanks so much for responding.

    I should have specified I need it to only intercept the requests that have /DocumentDownload/ in the request url. How would I amend your response to only filter for those requests?

  • Re: Rewriting route parameter

    Mar 27, 2020 01:34 AM|ct1|LINK

    Hi Jalpa - I was able to get your code working, it was good.  My issue was that my rules were set to wildcard instead of regex for some reason.  I changed that and it worked. Thanks!

  • Re: Rewriting route parameter

    Mar 27, 2020 01:36 AM|Jalpa Panchal|LINK

    Hi,

    If your issue is solved then I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue.

    If your issue still exists then try to refer the solution given by the community members.

    If then also you have any further questions then let us know about it.

    We will try to provide further suggestions to solve the issue.

    Thanks for your understanding.

    Regards

    Jalpa.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.