Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have successfully set up custom static error pages for IIS7. IIS7 is currently working as a gateway to a Java tomcat application. The issue is that when the 404 error page is served it is served with a HTTP 200 status code header. I would like a way to configure IIS to continue to send a HTTP 404. The error page exists as a static page in the webroot.

This is the main part of my web.config:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="HTTP to HTTPS Redirect" enabled="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
            </rule>
            <rule name="Reverse Proxy" stopProcessing="true">
                <match url="(.*)" />
                <action type="Rewrite" url="http://localhost:8080/{R:1}" />
                <conditions>
                    <add input="{R:1}" pattern="error/*." negate="true" />
                </conditions>
            </rule>
        </rules>
    </rewrite>
    <httpErrors errorMode="Custom" existingResponse="Auto">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/error/404.htm" responseMode="ExecuteURL" />
    </httpErrors>
</system.webServer>
share|improve this question
    
Does the error occur when accessing the page at site/error/440.htm, or only when redirected when an error occurs? –  Greg Askew Jun 22 '12 at 18:38
    
Both return a Status Code 200. I would expect going to error/404.htm would return a 200. But consider that foobar.htm doesn't exist. Browsing to foobar.htm would render the error/404.htm (which it does) and set the header status code to 404 (which it does not). –  Tiggerizzy Jun 22 '12 at 19:02
    
    
@GregAskew Neither of those address my issue. They both require the application behind IIS to do the reporting of the status code. This is something that any HTTP server should be able to do. And this is much more important for 502 and 503 status codes where the application behind the HTTP server is down. –  Tiggerizzy Jun 22 '12 at 21:21
    
Quick question: why responseMode="ExecuteURL"? You're serving a static file! –  Mathias R. Jessen Jun 24 '12 at 20:23

1 Answer 1

up vote 2 down vote accepted

Switch to using responseMode="File" however the trick with this is going to be using relative file paths unless you unlock or set to true system.webServer/httpErrors allowAbsolutePathsWhenDelegated.

Example web.config excerpt:

<httpErrors>
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="error\404.htm" responseMode="File" />
</httpErrors>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.