I had picked a task that stated to replace some error 500 status pages and to set them to 410 ‘Gone’ error status.

This was fiddly as the project is server under a proxy and both handle URL Rewrites.

I ended up adding a new rewrite rule:

<rule name="Return 410" enabled="true" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^(.*)\.ie(.*)$" negate="true" />
    <add input="{Static410:{REQUEST_URI}}" pattern=".+" />
  </conditions>
  <action type="CustomResponse" statusCode="410" subStatusCode="0" statusReason="Gone" statusDescription="Gone" />
</rule>

And created a new rewrite map ‘Static410’ that contained all the links that had to be redirected as 410 error page:

redirect1 redirect2

Notes: I had to add the rule at the top of the rule stack.

Resources used: