Question

I'm using IIS 7.5 and UrlRewrite Module 2. I've read the official documentation for the module here, as well as many examples on SO and tested my regex on Regexpal. Somehow the translation into the Web.config file is causing me problems. I've tried escaping the parantheses also.

The regex I'm using is:

^partners/(var|distributors|msp|techpartners)/(na|emea|apac)(|/)(.*)

a few example urls:

partners/var/emea

partners/msp/apac/

partners/var/na/abcdabcdabcd

Here is the web.config I have so far:

<rules>
  <rule name="partnersListing" enabled="true" stopProcessing="true">
    <match url="^partners/(var|distributors|msp|techpartners)/(na|emea|apac)(|/)(.*)" />
    <action type="Rewrite" url="partnersList.aspx?type=${R:1}&region={R:2}" />
  </rule>
</rules>

Not sure if I want the action to be Rewrite or Redirect yet, but the pattern isn't working either way. Any help is greatly appreciated

Was it helpful?

Solution

Per your answer to my question in the comments:

Is this rule in the site root web.config or a subdirectory web.config?

@Kev in a subdirectory: "/partners"

From the docs:

http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference?amp;clcid=0x409

Quote:

Note that the input URL string passed to a distributed rule is always relative to the location of the Web.config file where the rule is defined. For example, if a request is made for http://www.mysite.com/content/default.aspx?tabid=2&subtabid=3, and a rewrite rule is defined in the /content directory, then the rule gets this URL string default.aspx as an input.

Based on this you need to change your url match to:

^(var|distributors|msp|techpartners)/(na|emea|apac)(|/)(.*)

Assuming your re-write rule exists in:

http://example.com/partners/web.config

There is just one other thing which is what appears to be an extraneous $ character in your redirect/rewrite url in front of back reference {R:1}, I'm not sure if you intended that to be there or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top