IIS 7 returns HTTP 200 on custom 404 error page

http-headershttp-status-code-404iis-7

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>

Best Answer

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>