Reputation: 830
I have a question regarding to url rewrite in IIS. The question resembles URL Rewrite rule - subfolder to query string value quite a bit, but I fail to tailor the answer to my needs.
We have a REST interface that has this structure:
http://rest.company.nl:8090/interface.svc/accountmanager?customer=TEST
Now we want to add a company subfolder to the url and use URL Rewrite to be able to use the same rest application for all companies. It should work like this:
Should map to
I have written the following rule in IIS Site (with Append Query String and Log rewritten URL both checked):
<rule name="Company specific REST" patternSyntax="Wildcard" stopProcessing="true">
<match url="*/interface.svc/*" />
<action type="Rewrite" url="http://rest.company.nl:8090/interface.svc/{R:2}?company={R:1}" logRewrittenUrl="true" />
<conditions>
</conditions>
</rule>
From https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference I understand that the match in the rule will be compared to the path of the url. Now my path contains a file (interface.svc) rather than a folder. Could this cause a problem?
The response I get when I enter a company specific URL is a 404 and there is no log that sheds some light.
Thanks for your time!
Upvotes: 0
Views: 188
Reputation: 12759
There is some issue in your rule regular expression.
you could try to use the below rule:
<rule name="Company specific REST" patternSyntax="ECMAScript" stopProcessing="true">
<match url="interface.svc/(.*)/(.*)" />
<action type="Rewrite" url="http://rest.company.nl:8090/interface.svc/{R:2}?company={R:1}&{C:1}" appendQueryString="false" logRewrittenUrl="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)" />
</conditions>
</rule>
Upvotes: 1