强制使用.htaccess文件下载

编程入门 行业动态 更新时间:2024-10-28 22:24:09
本文介绍了强制使用.htaccess文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我在htaccess中使用以下规则:

So I am using the following rule in the htaccess:

AddType SCHM wsc <FilesMatch "\.(wsc)$"> ForceType SCHM Header set Content-Disposition attachment </FilesMatch>

当我转到文件的位置时,它不会强制下载

But when I go to the file's location it doesn't force the download

推荐答案

由于注释中已经回答了该问题,因此仅以Stackoverflow如何指定它的方式提供答案。

Since the question is already answered in the comments, this is just to provide an answer in the way how Stackoverflow designated it.

就像问题一样,可以使用 Apache 2 的 mod_headers 来解决。由于 Content-Disposition 不是 HTTP 标准的一部分,因此您可以添加其他标头来实现目标。

Like in the question it can be solved by using mod_headers of Apache 2. Since Content-Disposition is not part of the standard of HTTP, you may add some other header to achieve your objective.

<FilesMatch "\.(wsc)$"> Header set Content-Type application/octet-stream Header set Content-Disposition attachment </FilesMatch>

您应该考虑的另一件事是您的浏览器可能会缓存服务器的响应。浏览器仍将发送请求,但是该请求将包含一个节点,该节点浏览器已经具有给定日期的文件。如果自给定日期以来文件没有更改,则服务器不会将新标头发送到您的浏览器。这意味着,如果更改 .htaccess ,在禁用浏览器中的缓存或更改文件的时间戳之前,可能看不到任何影响。

Another thing you should consider is that your browser may cache the responce of the server. The browser will still send the request, but the request will contain a node that the browser already have the file from a given date. If the files hasn't changed since the given date, the server will not send the new headers to your browser. This means if you change the .htaccess, you may not see any impact until you disable caching in your browser or you change the timestamps of the file.

您还可以添加

Header set X-Content-Type-Options "nosniff"

具有更好的兼容性(也许还有安全性)。它可以防止浏览器进行MIME类型的嗅探,该方法将忽略声明的内容类型。有关更多信息,请参见此处。

for better compatiblity (and maybe security). It prevents the browser from doing MIME-type sniffing, which would ignore the declared content-type. See here for more information.

更多推荐

强制使用.htaccess文件下载

本文发布于:2023-10-31 11:48:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!