Apache 2.4 sets mime file type without extension

I upgraded from Apache 2.2 to 2.4 on a RedHat 6.4 server and ran into a mime type problem.

Apache has a default directive . In Apache 2.2, I set this value to "text / plain". I have a web page that lists all the files in this directory, and the user can click to view the files. This directory contains all types of different file extensions and some files without extensions. When a file is clicked, it will open in a new window, well formatted. No code does this. It is strictly a browser that opens a file and decides what to do by its type of content.

This directive is disabled in Apache 2.4. On the Apache documentation website, the user is prompted to use the mime.types and AddType Directive configuration file to configure media types.

My question is how to assign a mime type of type "text / plain" to files without extension? In Apache 2.2, these files will be assigned the default text / regular content type using the DefaultType directive. In Apache 2.4, I cannot figure out how to do this, since I can no longer use this directive. I do not want to use ForceType Directive because it will override other mime types that are already defined.

I could create a php wrapper that downloads the file and assigns a content type, but I would prefer to keep the logic in apache, where all the other definitions of the mime type are located.

Any help would be greatly appreciated. If you need more information, please let me know.

+6
source share
1 answer

Only files without extension

This solution only affects files without continuation, statically filed: (credit by Eugene Kerner )

<FilesMatch "^[^.]+$"> ForceType text/plain </FilesMatch> 

Any unknown content

This affects any response that would otherwise be transmitted without a Content-Type header. In other words, it mimics the behavior of the old DefaultType directive:

 Header set Content-Type "text/plain" "expr=-z %{CONTENT_TYPE}" 

It should be possible here to use setifempty instead of the -z expression. But it fails and overwrites the title in each answer, empty or not. I do not know why. Eric Covener says the Content-Type header has not been added "until the very last second."

+4
source

Source: https://habr.com/ru/post/984580/


All Articles