File extension handling
Most web servers have a default configuration
mapping file extensions like .html
or .txt
to corresponding mime-types like text/
or text/
.
The focus in this section is on handling multiple extensions like .html.
-
in general the last extension part (.txt
in .html.
) defines the mime-type:
file.
shall use mime-typehtml text/
html file.
shall use mime-typehtml. txt text/
plain file.
shall use mime-typehtml. wrong text/
(but especially notplain text/
)html
Apache's mod_mime documentation explains their handling of files having multiple extensions.
Directive Types
and using a mime.types map probably
leads to unexpected handling of extension .html.
as mime-type text/
:
AddType text/html html htm
AddType image/svg+xml svg svgz
Global settings like shown in the example above
are matching .html
and .html.
file extension
and have to be limited with <Files
:
<FilesMatch ".+\.html?$">
AddType text/html .html .htm
</FilesMatch>
<FilesMatch ".+\.svgz?$">
AddType image/svg+xml .svg .svgz
</FilesMatch>
In case these settings cannot be applied to the global server configuration,
but only to .htaccess
it is recommended to remove the default behavior:
RemoveType .html .htm
RemoveType .svg .svgz
The scenario is similar when it comes to evaluate PHP files -
it is totally expected and fine for files like test.
(ending with .php
) -
but it is definitively unexpected for files like test.
(having .php
somewhere in between).
The expected default configuration should look like the following (adjusted to the actual PHP script dispatching via CGI, FPM or any other type):
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>