Control Web Panel

WebPanel => Apache => Topic started by: Starburst on December 18, 2024, 04:03:07 PM

Title: Stop Apache from opening file
Post by: Starburst 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/ (https://mariadb.gb.ssimn.org/)

Need those files to download, instead of open.
Title: Re: Stop Apache from opening file
Post by: leisegang 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>
Title: Re: Stop Apache from opening file
Post by: Starburst 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.
Title: Re: Stop Apache from opening file
Post by: overseer 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>