How can I use the URL Rewrite module in IIS to mimic a generic 404 handler?

It is easy enough to set up rewrite rules that match a specific pattern, but what I want to do is to set up a rewrite rule for any URL that does not match an existing file on disk (or a virtual folder).

I also need to know what the original URL was, so I can process it further.

For example, given the following request


If "foobar" resolves to an actual folder/file (or virtual folder), it should be handled as normal by IIS.

If "foobar" does not exist (ie the server would normally return a 404), the rewrite rule should kick in and forward to another URL, for example


Is this possible using the URL Rewrite module? If not, how can I achieve it using other IIS tools/techniques?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.