Is it possible to write a regular expression that catches a match that others have missed in IIS?

Using URL Rewrite module v2:

<rule name="CatchAll" 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="/catchall.aspx?page={REQUEST_URI}" />
</rule>

This rule will catch ALL requests for non-existing files and directories. Usually you will place it at the end (the last or so).

All of such requests will be redirected (internally, of course) to /catchall.aspx file, the requested URL will be in page query string parameter. For example, if this page (http://www.example.com/hello-kitten) will be routed through such catch-all file it will be rewritten to /catchall.aspx?page=/hello-kitten.


{REQUEST_FILENAME}: The full local filesystem path to the file or script matching the request. For example:

  • Website root: D:\websites\mysite.com\
  • Requested URL: http://mysite.com/help/delivery
  • {REQUEST_FILENAME} = D:\websites\mysite.com\help\delievry (even if such file/folder does not exist) -- I'm sure you can figure out how it is built from the above example (if virtual folders get involved then it will work a bit differently .. but the general idea is here).

The conditions for this rule, if translated to English, would be: if requested resource is NOT a file AND is NOT a folder, then conditions are met.

URL Rewrite module has IsFile match type, but has no IsNotFile. To "simulate" IsNotFile the IsFile is used in conjunction with negate="true". The same goes for IsDirectory.

If you access URL Rewrite module via IIS Manager, and click "Edit" on this rule, you will have much easier time with understanding what they do exactly compared to my mumbling (IIS Manager has very good GUI for creating these rules).