I would like to rewrite the URL in IIS where the subdomain is rewritten. For instance:
www.mycompany.com/api/v1.0 copied to api1.mycompany.comwww.mycompany.com/api/v2.0 copied to api2.mycompany.com
Please note that I would like rewrite , not redirect , in other words, the URL in the browser remains www.mycompany.com/api/v1.0 and www.mycompany.com/api/v2.0 .
Any request that does not match the above patterns should continue to be processed by www.mycompany.com .
My understanding is that just one Rewrite 2.0 URL module is not enough for this to happen, so I installed Routing 3.0 applications. Here is a web.config example for what I'm trying to do:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <directoryBrowse enabled="false" /> <rewrite> <rules> <rule name="API v1.0" stopProcessing="true"> <match url="^api/v1.0/(.*)$" /> <action type="Rewrite" url="http://api1.mycompany.com/{R:1}" /> </rule> <rule name="API v2.0" stopProcessing="true"> <match url="^api/v2.0/(.*)$" /> <action type="Rewrite" url="http://api2.mycompany.com/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Once I set up application request routing, I managed to get this to work, but only if www.mycompany.com is the Default Website for IIS. In other words, only if IIS is configured like this:
- Default Website (
www.mycompany.com )- Web.config for this site is shown above.
api1.mycompany.comapi2.mycompany.com
My problem is that www.mycompany.com cannot be the Default Website (the default site is reserved by another site on the server). www.mycompany.com is another website similar to api1.mycompany.com or api2.mycompany.com . Is there a way to get this to work without www.mycompany.com being the Default Website ? Something like that?
- Default website (any other website not associated with it)
www.mycompany.com- Web.config for this site as shown above
api1.mycompany.comapi2.mycompany.com
source share