是否需要为 .exe 和 .htm 添加 "AddType" 行?
Is it necessary to add "AddType" line for .exe and .htm?
最近我检查了我的 .htaccess 文件,发现没有用于 .exe 和 .htm 文件类型的 AddType 行,如下所示:
<IfModule mod_mime.c>
AddType application/octet-stream .exe
AddType text/html .htm
</IfModule>
但是,奇怪的是浏览器仍然可以下载.exe文件,而不是在浏览器中显示。并显示 .htm 而不是下载它。为什么?是否需要为这两种类型添加“AddType”?
这些 mime-types 肯定已经在服务器配置中定义了。尽管不一定明确使用 AddType
指令。
但是,.exe
文件的 mime-type 更有可能被定义为 application/x-msdownload
(或可能 application/vnd.microsoft.portable-executable
),而不是 application/octet-stream
。请参阅此相关的 Whosebug 问题:Which MIME type is correct for the .exe file?
这些 mime-types 列在 mime.types
配置文件中(其位置由 mod_mime 的 TypesConfig
directive 定义)由 Apache/mod_mime 在启动时。 mime.types
包含 mime-type 到文件扩展名的映射列表。例如:
application/x-msdownload exe dll com bat msi
text/html html htm
完整列表:
https://github.com/apache/httpd/blob/trunk/docs/conf/mime.types
以及注册 mime-types 和 iana.org 的官方列表,请参阅:
https://www.iana.org/assignments/media-types/media-types.xhtml
the browser still can download .exe file instead of showing it in browser.
浏览器通常不知道如何处理“.exe
个文件”。如果浏览器收到它不理解的 mime-type (Content-Type
header) 的响应,它很可能会提示 download/save 它。
最近我检查了我的 .htaccess 文件,发现没有用于 .exe 和 .htm 文件类型的 AddType 行,如下所示:
<IfModule mod_mime.c>
AddType application/octet-stream .exe
AddType text/html .htm
</IfModule>
但是,奇怪的是浏览器仍然可以下载.exe文件,而不是在浏览器中显示。并显示 .htm 而不是下载它。为什么?是否需要为这两种类型添加“AddType”?
这些 mime-types 肯定已经在服务器配置中定义了。尽管不一定明确使用 AddType
指令。
但是,.exe
文件的 mime-type 更有可能被定义为 application/x-msdownload
(或可能 application/vnd.microsoft.portable-executable
),而不是 application/octet-stream
。请参阅此相关的 Whosebug 问题:Which MIME type is correct for the .exe file?
这些 mime-types 列在 mime.types
配置文件中(其位置由 mod_mime 的 TypesConfig
directive 定义)由 Apache/mod_mime 在启动时。 mime.types
包含 mime-type 到文件扩展名的映射列表。例如:
application/x-msdownload exe dll com bat msi text/html html htm
完整列表:
https://github.com/apache/httpd/blob/trunk/docs/conf/mime.types
以及注册 mime-types 和 iana.org 的官方列表,请参阅:
https://www.iana.org/assignments/media-types/media-types.xhtml
the browser still can download .exe file instead of showing it in browser.
浏览器通常不知道如何处理“.exe
个文件”。如果浏览器收到它不理解的 mime-type (Content-Type
header) 的响应,它很可能会提示 download/save 它。