如何检查子文件夹中的文件以进行IIS重写?

问题描述 投票:0回答:1

web.config中的以下内容用于重写工作正常

<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>

我想添加一个条件以确保仅当子文件夹中的压缩文件存在时才完成重写:

<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>

重写永远不会发生这种情况。这意味着检查总是返回false。我也尝试了以下方法使该条件无济于事:

<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" />

任何人都可以给这个小费吗?

编辑(2019-09-27):文件夹结构:

enter image description here

Web应用程序foo的目录是... \ dist。打开Web应用程序的URL是:http://localhost/foo/

编辑(2019-09-30):enter image description here

iis url-rewriting web-config
1个回答
0
投票
所以这是您需要的规则:

<rule name="foo" stopProcessing="true"> <match url="^foo\.dat$" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_ACCEPT_ENCODING}" pattern="br" /> <!-- {APPL_PHYSICAL_PATH} equals to {DOCUMENT_ROOT} + "dist\" in your setup --> <add input="{APPL_PHYSICAL_PATH}_compressed_br\foo.dat" matchType="IsFile" /> </conditions> <action type="Rewrite" url="_compressed_br/foo.dat" /> <serverVariables> <set name="RESPONSE_Content-Encoding" value="br" /> </serverVariables> </rule>

© www.soinside.com 2019 - 2024. All rights reserved.