大网数据广告活动
服务器运维问答

DefaultType directive in apache 2.4

· 52CE 我爱测

We have just migrated from Apache 2.0.53 to Apache 2.4 Everything works perfectly for html/js/css files etc. But we have a number of endpoints on our servers which return plain text. For example - an endpoint would return - RIL~R…

问题原文

原帖链接 · Arpit Agrawal · CC BY-SA 3.0

We have just migrated from Apache 2.0.53 to Apache 2.4 Everything works perfectly for html/js/css files etc.

But we have a number of endpoints on our servers which return plain text. For example - an endpoint would return -

RIL~Reliance Industries~1234~abcd

By default the response for these do not contain any "content-type" but I am expecting "text/plain"

In Apache 2.0.53 we were using

DefaultType text/plain

But in Apache 2.4 , this directive is disabled. (Ref:http://httpd.apache.org/docs/2.4/mod/core.html#defaulttype)

I have a large number of requests and want a generic solution that I can apply to my apache so that if there is no content-type provided, then it should send "text/plain"

Any suggestions please.

社区高分解答

原帖链接 · Nitrodist · CC BY-SA 3.0

One solution is to use ForceType text/plain to set the Content-Type header to text/plain. This will make all responses return text/plain, however.

A very specific problem in using ForceType is that it breaks mod_mime's file extension detection. For example, files requested with .css or .js extensions won't have their Content-Type set to text/css or application/javascript and will instead have it set to text/plain: probably not what you want.

As noted in a chain on the apache mailing list, the reason why DefaultType was removed is because they are now recommending that the browser do the sniffing to figure out the content-type. If you're upgrading from apache 2.2 to 2.4, then you should try to just use it without adding it back in.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-08-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。