[SOLVED] Redirect specific path to a different domain (ASP.NET + IIS)


This Content is from Stack Overflow. Question asked by perfect_element

I have a set of public API endpoints hosted with our main web app. They are all under the path /api/v1/. I want to move all API calls to a different domain, and keep the original path.

For example, a call to:


Should be redirected to:


What’s the best way to do this with ASP.NET (Framework 4.8) and IIS?

Note that I have other paths that I don’t want to be redirected, like /api/orders. The URL needs to have /api/v1/.

Thanks is advance.


You can use iis url rewrite to redirect your url, you can use this rule as a reference:

<rule name="test">
  <match url="^api/v1/(.*)$" />
        <add input="{HTTP_HOST}" pattern="^mydoamin.com$" />
  <action type="Redirect" url="http://api.mydomain.com/api/v1/{R:1}" />

This Question was asked in StackOverflow by perfect_element and Answered by samwu It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?