0

I'm attempting to setup a rewrite rule to return a 404 for a directory on an Azure Web App. We're using Sitecore, so I'd like to block access to the Sitecore admin interface on our delivery servers.

In my web.config, I've added the following rewrite rule

<rule name="Block Sitecore Access Rule" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{REQUEST_URI}" pattern="^/sitecore" />
    </conditions>
    <action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="Cause I said so" />
</rule>

However, this rule doesn't have any effect. If I change the status code to 403 like this, the rule does what I would expect:

<action type="CustomResponse" statusCode="403" statusReason="Not Found" statusDescription="Cause I said so" />

This indicates to me that the 404 is not allowed.

Do Azure Web Apps not support CustomResponse with 404, or is there something else I am missing?

0

Works for me if I just use the match instead of conditions. I tested with a rewrite to block access to an images directory, first with a 403:

<rule name="Test 404" stopProcessing="true">
    <match url="img/*" />
    <action type="CustomResponse" statusCode="403" />
</rule>

enter image description here

And then with a 404:

<rule name="Test 404" stopProcessing="true">
    <match url="img/*" />
    <action type="CustomResponse" statusCode="404" />
</rule>

enter image description here

Removing the rewrite:

enter image description here

Your Answer

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

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