【问题标题】:IIS Rewrite Content-Disposition attachment filenameIIS 重写 Content-Disposition 附件文件名
【发布时间】:2021-12-22 06:16:56
【问题描述】:

我在重写规则方面不是最棒的,但我正在尝试根据查询字符串将文件重命名为下载,例如像这样https://example.com/images/02ec1c94de50.jpg?download=1&filename=renamethefiletothis.jpg

这是我的规则,目前将文件硬编码为 thisfile.jpg 我想获取 URL 参数文件名并替换 thisfile.jpg

<rule name="Downloadthefile">
    <match serverVariable="RESPONSE_Content_Disposition" pattern=".*" />
    <action type="Rewrite" value="attachment;filename=thisfile.jpg" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="(^|&amp;)download=1(&amp;|$)"/>
    </conditions>
</rule>

谢谢

【问题讨论】:

  • 我不太明白你的意思。你的目标网址是什么?你想把这个 URL 改写成什么?
  • 它是在下载时重命名文件,因此当有人单击链接时,文件将以特定名称下载,我主要使用当前规则

标签: iis download url-rewriting url-rewrite-module content-disposition


【解决方案1】:

我能够得到一些工作,这并不完美,但工作。

所以这个 url 存储在服务器上的文件被称为 02ec1c94de50.jpg 但是当用户点击链接时它下载为 myrenamed.jpg

https://example.com/02ec1c94de50.jpg?&filename=myrenamed.jpg

下载属性,例如download="myrenamed" 不能跨域工作,所以必须使用 content-disposition 标头来动态重命名。

<rule name="Downloadthefile">
    <match serverVariable="RESPONSE_Content_Disposition" pattern=".*" />
    <action type="Rewrite" value="attachment;{C:0}" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="(^|&amp;)filename=(.*)$" />
    </conditions>
</rule>

【讨论】:

    猜你喜欢
    • 2015-07-17
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多