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="^([^=&]+)=([^=&]+)$" /> </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="^([^=&]+)=([^=&]+)$" /> </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
ortest2/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
ortest2
, 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
Post a Comment