【问题标题】:IIS URL rewrite conflict between files and urls文件和url之间的IIS URL重写冲突
【发布时间】:2019-09-14 21:02:38
【问题描述】:

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

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

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

所以,我需要能够访问此 url,但同时我需要能够下载“ics”文件。最好的方法是什么?

【问题讨论】:

    标签: iis url-rewriting


    【解决方案1】:

    您可以将条件模式从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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-11
      • 2012-10-09
      • 2011-10-08
      • 1970-01-01
      • 2015-04-15
      • 2019-11-24
      • 2012-05-23
      • 1970-01-01
      相关资源
      最近更新 更多