在 IIS 中。网站目录设置为C:\mywebiste,绑定8086端口,可以正常浏览以下网页:
https://localhost:8086/home/dist/
我想使用 IIS 重写以仅使用压缩的 foo.dat(如果存在),因此 web.config 如下所示:
<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="{APPL_PHYSICAL_PATH}home\dist\_compressed_br\foo.dat" matchType="IsFile" negate="false" />
</conditions>
<action type="Rewrite" url="_compressed_br/foo.dat" />
</rule>
它工作正常。由于我可能将dist文件夹下的内容分发到任意目录下对应的web.config,想知道有没有参数可以代替"{APPL_PHYSICAL_PATH}home\dist"这样我就可以使用同一个web.config我把它们放在哪里。这个问题是根据善良答案提供者的建议从另一个类似问题的扩展。
[编辑] 2019-10-03基于优秀的评论答案,我现在可以重写所有文件:
<rule name="Rewrite br" stopProcessing="true">
<match url="^(.*)$"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<!-- Match brotli requests -->
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br" />
<!-- following condition captures a group {C:1} with the value "C:\some\directory" for a path "c:\some\directory\foo.dat" -->
<!-- so we can use in the next condition to check whether the compressed version exists -->
<add input="{REQUEST_FILENAME}" pattern="^(.*)\\([^\\]*)$"/>
<!-- Check if the pre-compressed file exists on the disk -->
<!-- {C:1} used as requested file's parent folder -->
<add input="{C:1}\_compressed_br\{C:2}" matchType="IsFile"/>
</conditions>
<action type="Rewrite" url="_compressed_br/{C:2}" />
<serverVariables>
<set name="RESPONSE_Content-Encoding" value="br"/>
</serverVariables>
</rule>
如果我理解正确,您总是想重写 .xml_compressed_br
文件旁边的文件夹下的版本web.config
。
如果是这样,请尝试以下操作:
<rule name="foo" stopProcessing="true">
<match url="^foo\.dat$"/>
<!-- trackAllCaptures="true" is required to capture regex groups across conditions -->
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ACCEPT_ENCODING}" pattern="br"/>
<!-- following condition captures a group {C:1} with the value "C:\some\directory" for a path "c:\some\directory\foo.dat" -->
<!-- so we can use in the next condition to check whether the compressed version exists -->
<add input="{REQUEST_FILENAME}" pattern="^(.*)\\foo\.dat$"/>
<!-- {C:1} used as requested file's parent folder -->
<add input="{C:1}\_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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句