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?
IIS – Write Regular Expression to Catch Missed Matches
iisregular expressions
Best Answer
Using URL Rewrite module v2:
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 inpage
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:D:\websites\mysite.com\
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 noIsNotFile
. To "simulate"IsNotFile
theIsFile
is used in conjunction withnegate="true"
. The same goes forIsDirectory
.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).