4

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

lopata
  • 1,325
  • 1
  • 10
  • 23
  • Which browser are you using? My Chromium 45 downloads the file – Reeno Oct 17 '15 at 14:44
  • I am using Chrome, but [similar file](http://wsdb.fullwormage.com/738.wsc) on other site works for me , but with the one on my ftp it just shows the binary in the browser – lopata Oct 17 '15 at 14:49
  • Maybe you should also set `Content-Type` to `application/octet-stream`. I think somethink like this: `Header set Content-Type application/octet-stream` – JojOatXGME Oct 17 '15 at 14:58
  • @JojOatXGME I tried but it didn't work – lopata Oct 17 '15 at 15:03
  • Ok, since It had worked on my pc, I don't know why it does not work for you. I have seen that the server respons with "Not Modified" if I have the file already in the cache. Maybe your browser simply caches the file and doesnt know that you have added this header entries. In this case only a newer modification date of the file would cause a reload in your browser. You can use `touch ` in the shell of Linux to change the timestamps. – JojOatXGME Oct 17 '15 at 15:23
  • @JojOatXGME I cleared my cache, and not it works!! Thank you very much – lopata Oct 17 '15 at 15:27

2 Answers2

6

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.

Community
  • 1
  • 1
JojOatXGME
  • 3,023
  • 2
  • 25
  • 41
  • 1
    It is correct, but (although not enforced) the filename is appended after the attachment disposition type, and there are "some" browsers (IE) that sniff first few bytes of binary files to guess the mimetype, here is a complete(er) [solution](http://stackoverflow.com/a/34758866/257319) –  Jan 13 '16 at 05:49
1

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

SilentT
  • 125
  • 1
  • 1
  • 9