asp.net - IIS Rewrite root folder to different subfolders -
i'm setting folder structure inside application looks such:
- c:\inetpub\wwwroot\contoso\public
- c:\inetpub\wwwroot\contoso\secured
i wanting map following urls folder structures:
- http://www.contoso.com/login -> \public\login.aspx
- http://www.contoso.com/myaccount -> \secured\myaccount.aspx
- http://www.contoso.com/(css|images|js)/* -> \public(css|images|js)* (not represented in below rules)
i have application request routing version 2 installed on server. thought process build few rewrite rules mapping me such these ...
<rewrite> <rules> <rule name="rewrite pub page aspx" stopprocessing="false"> <match url="^([a-z0-9/]+)$" ignorecase="true" /> <conditions> <add input="public\{request_filename}.aspx" matchtype="isfile" ignorecase="true" /> </conditions> <action type="rewrite" url="public/{r:1}.aspx" /> </rule> <rule name="rewrite sec page aspx" stopprocessing="false"> <match url="^([a-z0-9/]+)$" ignorecase="true" /> <conditions> <add input="secured\{request_filename}.aspx" matchtype="isfile" ignorecase="true" /> </conditions> <action type="rewrite" url="secured/{r:1}.aspx" /> </rule> <rule name="rewrite 404 page aspx" stopprocessing="true"> <match url="^([a-z0-9/]+)$" ignorecase="true" /> <conditions> <add input="{request_filename}" matchtype="isfile" negate="true"/> <add input="{request_filename}" matchtype="isdirectory" negate="true"/> </conditions> <action type="rewrite" url="public/default.aspx" /> </rule> </rules> </rewrite> <location path="secured"><system.web><authorization><deny users="?"/></authorization></system.web></location> <location path="public"><system.web><authorization><allow users="?,*"/></authorization></system.web></location>
in mind, telling condition check if file exists in public folder , if rewrite file. otherwise it'd fall through , see if file exists in secured folder , if rewrite file. otherwise caught "catch else" rule , point default page.
but not working expectations ... can rewrite folder can't conditions fire check file existing.
any suggestions?
i turned tracing on within iis , looking through logs able discover {request_filename} wrong variable use in situation. here's relevant log information:
input secured\{request_filename}.aspx expandedinput secured\c:\inetpub\wwwroot\contoso\myaccount.aspx matchtype 1 pattern negate false succeeded false matchtype isfile
so went looking through server variables list documentation , able find appl_physical_path variable , changed inputs this:
<rule name="rewrite sec page aspx" stopprocessing="false"> <match url="^([a-z0-9/]+)$" ignorecase="true" /> <conditions> <add input="{appl_physical_path}secured\{r:1}.aspx" matchtype="isfile" ignorecase="true" /> </conditions> <action type="rewrite" url="secured/{r:1}.aspx" /> </rule>
and voila, started matching. hope helps else in future.
Comments
Post a Comment