I have written a list of regular expressions that currently redirect unused pages to the appropriately used pages e.g. if someone were to request abc.aspx it redirects them to home.aspx in IIS however seeing that I cannot account for all pages is there a way to capture a page that I may have missed and map it to another page?

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).

Thanks Lazy One. Would you mind elaborating on the input types e.g. {REQUEST_FILENAME} as well as the matchtypes including the negate values? For example what they are, when I should use them and what they do.
–
PeanutsMonkeyJul 12 '11 at 22:21

That's fantastic. Thanks for elaborating on these. To clarify my understanding so that I am not confused. If I use the matchtype IsFile and set the negate value as true I am effectively saying if the request is NOT a file. If that is correct, I am confused by how would a requested file e.g. example.aspx be treated? Also just to be clear if I set the value of negate to false I take it means that if the requested file or folder is indeed a file or folder. Is that also correct?
–
PeanutsMonkeyJul 12 '11 at 22:44

1) Yes; 2) /example.aspx if such file DOES exist but condition says "Is Not File", then condition is not met and rewrite will not occur; 3) I actually do not know if you can set negate="false" -- instead just do not use this param, i.e. <add input="{REQUEST_FILENAME}" matchType="IsFile" />; 4) As you can see there are separate checks for File and Directory. There is no IsExist match type (it is all done similarly to Apache's mod_rewrite, which is a good thing as existing rules can be easily transferred/transformed into URL Rewrite rules).
–
LazyOneJul 12 '11 at 22:56

Thanks LazyOne. I am confused by what you mean by if the file DOES exist? Do you mean if it exists physically on the file system? If yes, what if the file exists as a database created page?
–
PeanutsMonkeyJul 12 '11 at 22:59