'Redirect to root page on 403 response

I have a React App hosted on IIS. If I access an existing directory, such as <app_url>/static/, it returns a 403 response since there's no permission on that directory. I'd like to redirect the user to my root page (~/).

I have tried this:

<httpErrors>
    <remove statusCode="403" subStatusCode="-1" />
    <error statusCode="403" prefixLanguageFilePath="" path="/" responseMode="ExecuteURL" />
</httpErrors>

This kinda works, it does return the root page, however, it tries to download the React bundles from /static/ instead of '/' only.

What can I do here?



Solution 1:[1]

I used this rule and it worked:

<rewrite>
    <rules>
        <rule name="Redirect Static" patternSyntax="ExactMatch" stopProcessing="true">
            <match url="static" />
            <action type="Redirect" url="/" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

(Thanks to @samwu)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mari Faleiros