'How to restrict access to folder by user-agent on Windows Server 2019?

I have a solution that runs on a web page on several different websites that uses JS files stored on Windows Server 2019, like with a CDN. The JS files are to be used by one particular web browser only, for example "Firefox", and only that browser should ever be using those files. So I am wondering if we can configure the server to only allow access to the JS folder by that browser. Is that possible and how?



Solution 1:[1]

From IIS Manager you can use UrlRewrite to set the redirect in web.config...

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Non-Firefox Redirect" stopProcessing="true">
                    <match url="^foldername/.*$" />
                    <conditions>
                        <add input="{HTTP_USER_AGENT}" pattern="Firefox" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://example.com/somepage.html" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
        </system.webServer>
</configuration>

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 WilliamK