IIS Api重定向规则
问题描述:
我需要一些帮助,在我的web.config中使用重定向正则表达式。我有一个网站用户界面和一个应用程序用户界面,它们打击相同的服务器端API,但是我将从URL中取消调用的URL与解析API更新的未来验证应用程序解耦。IIS Api重定向规则
这是我到目前为止在我的web.config中,它的作用是将api.mywebsite.com重定向到mywebsite.com,但是如何编写正则表达式来在最后添加版本,以便http://api.mywebsite.com/v1/被重定向到http://www.mywebsite.com?
<rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(api\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://dev.blahblah.org.au{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
答
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(api\.)(.*)$" />
<add input="{PATH_INFO}" pattern="^/v(\d+)/(.*)$" />
</conditions>
<action type="Redirect" url="http://localhost{PATH_INFO}?v={C:1}" redirectType="Permanent" />
</rule>
+0
这是我们需要的东西。但在我们的情况中,唯一的区别是使用action type =“Rewrite”进行传输而不是重定向。 – HCdev
岂不的**(*)**捕捉**/V1/**?或者我错过了什么? –
随着你的设置它应该已经是这种情况。你的'url =“^(。*)$”'匹配你的'v1 /'和'input =“{HTTP_HOST}”pattern =“^(api \。)(。*)$”'匹配'api。 mywebsite.com'。 – cheesemacfly