IIS URL Rewrite 2 different URLs in one Rule using Conditions, is it possible?

49 views Asked by At

I have two different rewrite rules.

<rule name="Venue" stopProcessing="true">
    <match url="Venue/([_0-9a-z-(-)-,-]+)/([_0-9a-z-(-)-,-]+)" />
    <action type="Rewrite" url="Main.asp?Type=Venue&amp;VenueID={R:1}&amp;VName={R:2}" appendQueryString="true" />
 </rule>
 <rule name="Venue" stopProcessing="true">
    <match url="Venue/([_0-9a-z-(-)-,-]+)/([_0-9a-z-(-)-,-]+)/([_0-9a-z-(-)-,-]+)" />
    <action type="Rewrite" url="Main.asp?Type=Venue&amp;VenueID={R:1}&amp;VName={R:2}&amp;ConcertID={R:3}" appendQueryString="true" />
  </rule>

Is there a way to combine both rules into a single rule using <conditions>?
So when you go to either URL.

/Venue/37/The_Omni (You go to its page.)

/Venue/37/The_Omni/ConcertID/1 (You go to its page.)

(OR) Will I have to settle with two rules but with different names?

1

There are 1 answers

2
Lex Li On

Literally regular expression rules allow you to write,

<rule name="Venue" stopProcessing="true">
    <match url="Venue/([_0-9a-z-(-)-,-]+)/([_0-9a-z-(-)-,-]+)(?:/([_0-9a-z-(-)-,-]+))?" />
    <action type="Rewrite" url="Main.asp?Type=Venue&amp;VenueID={R:1}&amp;VName={R:2}{R:3:+&amp;ConcertID={R:3}}" appendQueryString="true" />
</rule>

You might try and see if IIS URL Rewrite module supports such expressions.