asp.net - Regex to extract a part out of a URL and use it as a reference in 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. think have regex correct this, it's implementing in web.config causing problem.

so 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:

http://example.com/ca/en/ppf

(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, iis balking , saying web.config invalid. specifically, says "entity '(' not defined" , it's pointing ( right before language problem. so, can't build or deploy application till fix that. if build without , try drop web.config, error loading site:

http error 500.19 - internal server error requested page cannot accessed because related configuration data page invalid.

can me figure out how put capture group rewrite rule properly?

you forgot code ampersand. should be:

<system.webserver> <rewrite>   <rules>     <rule name="test" stopprocessing="true" enabled="true">       <match url="https?://of.example.com/sfsv3.aspx\?waform=pro&amp;(language=(..))" ignorecase="true" />       <action type="redirect" url="http://www.example.com/ca/{r:2}/ppf" />     </rule>   </rules> </rewrite> 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -