I have a local IIS server hosting Asp.net Core 3.1 web API running at port 5000.
Using wireguard the local server is connected with the public facing server.
The public facing server also has IIS 10 with ARR3.0 enabled & have the site created as https://api.example.com
.
Using IIS as reverse proxy the local API has been exposed & is being consumed by the mobile app.
The following Url Rewrite rule has been written in web.config:-
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://192.168.2.79:5000/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://192.168.2.79:5000/(.*)" />
<action type="Rewrite" value="http{R:1}://api.example.com/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
<add input="{RESPONSE_CONTENT_TYPE}" pattern=".*/.*" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
The API works just fine & return all response.
The problem comes when the API response return dynamically generated Image Url's which is correct if directly deployed on the server, but behind the Reverse Proxy its returning the local Url, which is not correct.
I want to rewrite the Base Url's in the API response body. how can I do that?
Code for Dynamically Generating Image Url:-
Please let me know, how can I rewrite the base url inside API response body?