[英]Redirect specific path to a different domain (ASP.NET + IIS)
I have a set of public API endpoints hosted with our main web app.我有一组由我们的主要 web 应用程序托管的公共 API 端点。 They are all under the path /api/v1/.
它们都在路径 /api/v1/ 下。 I want to move all API calls to a different domain, and keep the original path.
我想将所有 API 调用移动到不同的域,并保留原始路径。
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?使用 ASP.NET(框架 4.8)和 IIS 执行此操作的最佳方法是什么?
Note that I have other paths that I don't want to be redirected, like /api/orders.请注意,我还有其他不想重定向的路径,例如 /api/orders。 The URL needs to have /api/v1/.
URL 需要有 /api/v1/。
Thanks is advance.谢谢是提前。
You can use iis url rewrite to redirect your url, you can use this rule as a reference:您可以使用 iis url 重写来重定向您的 url,您可以使用此规则作为参考:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.