I would like a regex string to reflect an optional parameter, in this case, a geographic state.
I can accomplish this with two rules:
<rewrite url="~/(.+)-(.+)/(.+).aspx" to="~/Default.aspx?city=$1&state=$2&term=$3&x=$4"/>
<rewrite url="~/(.+)/(.+).aspx" to="~/Default.aspx?city=$1&state=NONE&term=$2&x=$4"/>
With, a query to /Los+Angeles/cars.aspx:
Geo – city: Los Angeles
Geo – state: NONE
With, a query to /Los+Angeles-CA/cars.aspx:
Geo – city: Los Angeles
Geo – state: CA
I’m curious about if there is a way to do this in one rewrite statement.
Thanks.
Have not messed with rewrite url in the config in a while but am quite used to regex. Would this work for you?
The state would not say none but should actually be blank.