简体   繁体   English

IIS Api重定向规则

[英]IIS Api redirect rule

I need some help with a redirect regex in my web.config. 我在web.config中需要有关重定向正则表达式的帮助。 I have a website UI and an App UI which hit the same serverside API but I'm decoupling the urls that get called from either for future-proofing the app against API updates. 我有一个网站用户界面和一个应用程序用户界面,它们使用相同的服务器端API,但我正在将两者中调用的网址分离,以便将来针对API更新来验证应用程序。

This is what I have so far in my web.config and it works for redirecting api.mywebsite.com to mywebsite.com, but how do I write the regex to add the version at the end so that http://api.mywebsite.com/v1/ gets redirected to http://www.mywebsite.com ? 这是我到目前为止在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM