The site I'm working on (.Net 4.0 & VS2010 on IIS8) uses a single rule to rewrite all incoming URLs to .aspx pages existing in a single "/pages/" folder. For example, "www.site.com/hello" is rewritten to "/pages/hello.aspx".
The current rewrite rule is this:
<rule name="pages" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^([a-z0-9_-]+(?:/[a-z0-9_-]+)*)/?$"/>
<action type="Rewrite" url="/pages/{R:1}.aspx" appendQueryString="true" />
</rule>
This is working fine, but I'm struggling to implement a custom 404 redirection for when either of the following are true:
a) The url format defined in the regex is not matched (i.e. the strict url format was not adhered to), or
b) The url regex is matched, but the rewrite to url="/pages/{R:1}.aspx"
does not exist (e.g. the url is "/pages" but the physical file "/pages/hello.aspx" does not exist).
Can that be accomplished with rewite rules?