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>
Switch to using
responseMode="File"
however the trick with this is going to be using relative file paths unless you unlock or set to truesystem.webServer/httpErrors allowAbsolutePathsWhenDelegated
.Example web.config excerpt:
When using
executeURL
, the file should be something that renders dynamically (a la .asp). The file executed must contain a script that sets the response status code.Example:
<% response.status = "404 Page Not Found" %>
Have you tried changing
ExecuteURL
toRedirect
in theresponseMode
attribute?Reference: https://techcommunity.microsoft.com/t5/iis-support-blog/issue-iis-logs-200-status-code-instead-of-404/ba-p/297652