简体   繁体   中英

IIS Api redirect rule

I need some help with a redirect regex in my 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.

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 ?

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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