asp.net - Regex to redirect a url using url rewrite -
ok, i'm wondering if can lend hand regex i'm trying write.
basically, want use iis urlrewrite module redirect specific url if user accesses url on site. catch have capture bit of query string, , move redirect.
here input, url user may access like:
https://of.example.com/sfsv3.aspx?waform=pro&language=en
i want match url (either http or https, case insensitive), , capture 1 piece of information, 2 letter language code. url want forward user looks like:
(where en replaced whatever captured above)
so, i'm working iis rewrite module, , i've gotten input data , regex in, far regex pattern have this:
https?://of.example.com/sfsv3.aspx\?waform=pro&(language=(..))
so i'm matching whole string, plus group , subgroup language , it's code. in iis test pattern dialog, working.
i following
{r:1} language=en
{r:2} en
great! iis rewrite rule should redirect user:
<system.webserver> <rewrite> <rules> <rule name="test" stopprocessing="true" enabled="true"> <match url="https?://of.example.com/sfsv3.aspx\?waform=pro&(language=(..))" ignorecase="true" /> <action type="redirect" url="http://www.example.com/ca/{r:2}/ppf" /> </rule> </rules> </rewrite> </system.webserver>
this seems right me. however, redirect not occurring. seems have problem part \? (an escaped question mark mark start of query string). if included, redirect not happen.
can me figure out how work?
for record, figured out. special case of regex, running inside web.config part of urlrewrite action. in case, can't handle query string simple regex, have put in conditions on query string. here's ended working:
<system.webserver> <rewrite> <rules> <rule name="redirect" stopprocessing="true" stopprocessing="true" enabled="true"> <match url="sfsv3.aspx\.aspx" ignorecase="true"/> <conditions> <add input="{query_string}" pattern="subject=proprch" /> <add input="{query_string}" pattern="(..)/subject" /> </conditions> <action type="redirect" url="https://www.example.com/ca/{c:1}/forms/ppf" appendquerystring="false"/> </rule> </rules> </rewrite> </system.webserver>
Comments
Post a Comment