IIS 【URL重寫】入站規則
參考博客:https://www.cnblogs.com/jsonzheng/articles/6606143.html
安裝ARR
下載安裝ARR(Application Request Routing),可通過【Web平臺安裝程序】,安裝成功後會多出 【Application Request Routing Cache】和【URL重寫】圖標,如下圖:
本文解決的主要問題
將對http://192.168.31.113:8101/api/xxx
的請求轉發至http://192.168.31.110:2893/Web/WebService/xxx
匹配URL規則
^(.*?)/?api/(.*)$
條件規則
{HTTP_HOST}
^192.168.31.113:8101$
操作規則
http://192.168.31.110:2893/Web/WebService/{R:2}
配置完後站點目錄下的web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="^(.*?)/?api/(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^192.168.31.113:8101$" />
</conditions>
<action type="Rewrite" url="http://192.168.31.110:2893/Web/WebService/{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>