url rewriting - Url rewrite base on query IIS asp.net -


i'm doing first time need help. how make code url rewrite 2.0 url rewrite base on query.

i need to:

www.example/ekonomija/ekonomija.aspx?ekonomija=something 

to be

www.example/ekonomija/something 

and

www.example/test2/test2.aspx?test2=something 

to be

www.example/test2/something 

and

www.example/test3/test3.aspx?test3=something 

to be

www.example/test3/something 

and on ....

need solution url rewrite: 2.0

edited try.... have problem first role working second no, query string not not accurately done, don't know.

<rule name="redirectuserfriendlyurl1" stopprocessing="true">                 <match url="^ekonomija/ekonomija\.aspx$" />                 <conditions>                     <add input="{request_method}" pattern="^post$" negate="true" />                     <add input="{query_string}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />                 </conditions>                 <action type="redirect" url="{c:1}/{c:2}" appendquerystring="false" />             </rule>             <rule name="rewriteuserfriendlyurl1" stopprocessing="true">                 <match url="^([^/]+)/([^/]+)/?$" />                 <conditions>                     <add input="{request_filename}" matchtype="isfile" negate="true" />                     <add input="{request_filename}" matchtype="isdirectory" negate="true" />                 </conditions>                 <action type="rewrite" url="ekonomija/ekonomija.aspx?{r:1}={r:2}" />             </rule>             <rule name="redirectuserfriendlyurl2" stopprocessing="true">                 <match url="^test2/test2\.aspx$" />                 <conditions>                     <add input="{request_method}" pattern="^post$" negate="true" />                     <add input="{query_string}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />                 </conditions>                 <action type="redirect" url="{c:1}/{c:2}" appendquerystring="false" />             </rule>             <rule name="rewriteuserfriendlyurl2" stopprocessing="true">                 <match url="^([^/]+)/([^/]+)/?$" />                 <conditions>                     <add input="{request_filename}" matchtype="isfile" negate="true" />                     <add input="{request_filename}" matchtype="isdirectory" negate="true" />                 </conditions>                 <action type="rewrite" url="test2/test2.aspx?{r:1}={r:2}" />             </rule> 

it might work first 1 never work second.
why?

because have 2 rules matching same conditions: rewriteuserfriendlyurl1 , rewriteuserfriendlyurl2

in case, second 1 never executed because processed in order , first 1 take over.

anyway, have tried simplify rules following:

<rule name="redirect rule" stopprocessing="true">     <match url="^(ekonomija/ekonomija|test2/test2)\.aspx$" />     <conditions>                                                                 <add input="{request_method}" pattern="^post$" negate="true" />         <add input="{query_string}" pattern="^(\w+)=(\w+)$" />     </conditions>                                                 <action type="redirect" url="{c:1}/{c:2}" appendquerystring="false" /> </rule> <rule name="rewrite rule" stopprocessing="true">     <match url="^(ekonomija|test2)/(\w+)$" />      <conditions>         <add input="{request_filename}" matchtype="isfile" negate="true" />         <add input="{request_filename}" matchtype="isdirectory" negate="true" />     </conditions>     <action type="rewrite" url="{r:1}/{r:1}.aspx?{r:1}={r:2}" /> </rule> 

the redirect working when

  • the requested url either ekonomija/ekonomija.aspx or test2/test2.aspx
  • the method used access url not post
  • the query string 1 alphanumeric sequence followed equal sign (=) followed second alphanumeric sequence

in case, redirect using references query string (first sequence/second sequence).

we have rewrite rule working when

  • the requested url starts ekonomija or test2, followed slash (/) , contains 1 or more alphanumeric character(s) after
  • the requested url doesn't match path file or directory on server

in case, rewrite using references requested url.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -