I'm setting up a folder structure inside an application that looks like such:
- c:\inetpub\wwwroot\contoso\public
- c:\inetpub\wwwroot\contoso\secured
I am wanting to map the following URLs to those 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 the Application Request Routing Version 2 installed on the server. My thought process was that I could build a few rewrite rules to do the mapping for me such as these ...
<rewrite>
<rules>
<rule name="Rewrite pub page to 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 to 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 to 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 my mind, I was telling the condition to check if the file exists in the public folder and if so it would rewrite that file. Otherwise it'd fall through and see if the file exists in the secured folder and if so it would rewrite that file. Otherwise it would get caught by the "catch everything else" rule and just point it back to a default page.
But this is not working to my expectations ... I can get it to always rewrite to a folder but I can't get the conditions to fire to check for a file existing.
Any suggestions?