perfect_element
perfect_element

Reputation: 683

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

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:

https://mydoamin.com/api/v1/client/123

Should be redirected to:

https://api.mydomain.com/api/v1/client/123 

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.

Upvotes: 0

Views: 196

Answers (1)

samwu
samwu

Reputation: 5205

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/(.*)$" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^mydoamin.com$" />
    </conditions>
  <action type="Redirect" url="http://api.mydomain.com/api/v1/{R:1}" />
</rule>

Upvotes: 1

Related Questions