Recently I review my .htaccess file and notice there are no AddType line for .exe and .htm file types, like below:
<IfModule mod_mime.c>
AddType application/octet-stream .exe
AddType text/html .htm
</IfModule>
However, the strange thing is that the browser still can download .exe file instead of showing it in browser. And showing .htm instead of download it. Why? And is it necessary to add "AddType" fro these two types?
CodePudding user response:
These mime-types are most certainly already defined in the server config. Although not necessarily explicitly with the AddType
directive.
However, the mime-type for .exe
files is more likely to be defined as application/x-msdownload
(or possibly application/vnd.microsoft.portable-executable
), rather than application/octet-stream
. See this related StackOverflow question: Which MIME type is correct for the .exe file?
These mime-types are listed in the mime.types
config file (the location of which is defined by mod_mime's TypesConfig
directive) that is read in by Apache/mod_mime at startup. mime.types
contains a list of mappings of mime-type to file extension. For example:
application/x-msdownload exe dll com bat msi text/html html htm
For the complete list:
https://github.com/apache/httpd/blob/trunk/docs/conf/mime.types
And for the official list of registered mime-types with iana.org, see:
https://www.iana.org/assignments/media-types/media-types.xhtml
the browser still can download .exe file instead of showing it in browser.
Browser's don't normally known how to handle ".exe
files". If the browser receives a response with a mime-type (Content-Type
header) that it does not understand it will most likely prompt to download/save it.