.htaccess - 在 htaccess 中使用 <filesMatch> 强制下载

标签 .htaccess

我试图强制下载一个文件夹的所有文件。

页面上的链接看起来像这样

<a href="http://example.com/uploads/documents/file.pdf">Click to download</a>

我的 .htaccess 中有这个片段
<filesMatch ".*uploads/documents.*">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</filesMatch>

我已经知道标签内的 2 行是有效的,因为当我将 .htaccess 直接放在我想使用以下代码强制下载的文件夹中时它有效:
<Files *.*>
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</Files>

我似乎对 filesMatch 标签有些不理解。

最佳答案

搜索更多信息发现此代码:

<FilesMatch "\.(mov|mp3|jpg|pdf|mp4|avi|wmv)$">
   ForceType application/octet-stream
   Header set Content-Disposition attachment
</FilesMatch>

为我工作。

关于.htaccess - 在 htaccess 中使用 <filesMatch> 强制下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14388994/

相关文章:

php - .htaccess 将我的索引更改为相关页面

.htaccess - 适用于 Internet Explorer 11 的 SSLCipherSuite

php - htaccess 重定向到父文件夹 index.php 如果不存在

apache - 如何将本地 IP 地址读入 .htaccess 文件?

apache - 如何使 mod_rewrite 抑制处理更多规则?

php - Htaccess - Http 身份验证 - 为什么此 block 对我造成 500 错误?

html - 无法使用 301 和 .htaccess 重定向

.htaccess - 如何通过 Apache2 发送压缩(放气)的 SVG?

linux - .htaccess - 将子目录添加到所有目录

apache - 如何根据域有条件地向 Apache .htaccess 添加一行?