Author Topic: Stop Apache from opening file  (Read 67 times)

0 Members and 1 Guest are viewing this topic.

Offline
*****
Stop Apache from opening file
« on: December 18, 2024, 04:03:07 PM »
Anyone know how to stop Apache from opening a text file that has no extension.

e.g. TIME, PublicKey, etc. - Basically anything without an extension.

Ref. https://mariadb.gb.ssimn.org/

Need those files to download, instead of open.

Offline
*
Re: Stop Apache from opening file
« Reply #1 on: December 18, 2024, 06:22:10 PM »
IF you make a simple HTML page with the following code it will be downloaded as a file:

Code: [Select]
<a href="somepathto.pdf" download="filename">
If you have Apache add this to the .htaccess file:

Quote
<FilesMatch "\.(?i:pdf)$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</FilesMatch>

Offline
*****
Re: Stop Apache from opening file
« Reply #2 on: December 18, 2024, 07:03:04 PM »
Thanks for the suggestions, got it working with a .htaccess

Where I was trying was under <Directory> I was trying to figure out how to put it there.
Currently:

Quote
AddType application/octet-stream .iso
AddType application/octet-stream .rpm

Tried adding:
Quote
ForceType application/octet-stream TIME
But didn't work.

Offline
*****
Re: Stop Apache from opening file
« Reply #3 on: December 18, 2024, 08:04:46 PM »
I think you're on the right track, but maybe set it more broadly?
Code: [Select]
DefaultType application/octet-stream
Or did you try the Content-Disposition header?
Code: [Select]
<filesMatch "^([^.]+)$">
Header set Content-Disposition "attachment"
</filesMatch>