lopata
lopata

Reputation: 1365

Force file to download with .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

Upvotes: 4

Views: 4371

Answers (2)

JojOatXGME
JojOatXGME

Reputation: 3296

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

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>

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.


You can also add

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

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.

Upvotes: 6

SilentT
SilentT

Reputation: 135

RFC2616 say for 19.5.1 Content-Disposition

If this header is used in a response with the application/octet- stream content-type, the implied suggestion is that the user agent should not display the response, but directly enter a `save response as...' dialog.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1

Upvotes: 1

Related Questions