IIS URL 重写文件和 URL 之间的冲突



我在我的 IIS 中有以下用于重写 url 的配置

<rewrite>
<rules>
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>

否定指令用于防止重写网站资产文件(css、字体等(以及文档上传/下载部分的其他文件。

我刚刚遇到的问题是,其中一个 url 是这样的 http://intranet/HR/Training-Basics 但是当我尝试导航到这个 url 时,我得到 404,因为它被文件扩展名 ics 的否定函数捕获。

因此,我需要能够访问此URL,但同时我需要能够下载" ics"文件。最好的方法是什么?

您可以将条件模式从 ics 修改为 \.ics,以便重写规则仅根据文件扩展名而不是特定字符串段重写。

<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern=".(css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>

最新更新