The following in web.config for rewrite works fine:
<rule name="foo" stopProcessing="true">
<match url="foo.dat$"/>
<conditions>
<!-- Match brotli requests -->
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
</conditions>
<action type="Rewrite" url="_compressed_br/foo.dat" />
</rule>
I want to add a condition to make sure the rewriting is done only if the compressed file in the sub-folder exists:
<rule name="foo" stopProcessing="true">
<match url="foo.dat$"/>
<conditions>
<!-- Match brotli requests -->
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
<!-- Check if the pre-compressed file exists on the disk -->
<add input="{DOCUMENT_ROOT}/_compressed_br/foo.dat" matchType="IsFile" negate="false" />
</conditions>
<action type="Rewrite" url="_compressed_br/foo.dat" />
</rule>
The rewriting never happens with the condition. This means the checking always returns false. I have also tried the following for the condition to no avail:
<add input="{DOCUMENT_ROOT}_compressed_br/foo.dat" matchType="IsFile" negate="false" />
<add input="/_compressed_br/foo.dat" matchType="IsFile" negate="false" />
<add input="_compressed_br/foo.dat" matchType="IsFile" negate="false" />
Could you anyone offer a tip on this?
Edit (2019-09-27): Folder structure:
Web app foo's directory is ...\dist. The URL to open the web application is: http://localhost/foo/
Edit (2019-10-01):
The accepted answer works like a charm for the above problem.
I have a new challenge. If I put the web file in the following directory: C:\mywebsite\home\dist\web.config
The website is bound to port 8086. I can browse the following web page: https://localhost:8086/home/dist/
To make the rewrite work, I would have to use the following:
<add input="{APPL_PHYSICAL_PATH}home\dist\_compressed_br\foo.dat" matchType="IsFile" negate="false" />
Since I may put the contents under folder dist with the corresponding web.config in any directory, I am wondering if there is a parameter that can replace "{APPL_PHYSICAL_PATH}home\dist" so that I can use the same web.config no matter where I put them.