我试图强制下载一个文件夹的所有文件。
页面上的链接看起来像这样
<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/