如何让 Apache2 以内容类型“text/html”而不是“text.html”的形式提供 .shtml 文件?

Chr*_*ard 3 server-side-includes apache-2.2

我正在一个网站上工作,实现为 shtml,当我尝试从 IE8加载主页 ( http://simplyclassicremodeling.com ) 时,它说它无法打开文件,因为它作为内容类型传输“文本.html”。该页面从 Chrome 加载正常,并在 Firefox 中加载(有一些与此处无关的 CSS 问题)。

httpd.conf 有:

Options Includes Indexes FollowSymLinks ExecCGI 
AddHandler cgi-script .cgi .pl
AddType text/html .shtml
AddHandler server-parsed .shtml
Run Code Online (Sandbox Code Playgroud)

再往下:

AddType text/html .shtml 
AddOutputFilter INCLUDES .shtml
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript application/javascript
Run Code Online (Sandbox Code Playgroud)

来自 Telnet 会话的 HTTP 标头是:

GET http://simplyclassicremodeling.com/ HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 27 Jan 2012 21:57:54 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.9-dev DAV/2 PHP/5.2.6
Accept-Ranges: bytes
Cache-Control: max-age=2592000, public
Expires: Sun, 26 Feb 2012 21:57:54 GMT
X-UA-Compatible: IE=Edge,chrome=1
Connection: close
Content-Type: text.html
Run Code Online (Sandbox Code Playgroud)

“AddType”和“AddOutputFilter”是否调换了?根据这些信息,您知道为什么 IE8 会认为 .shtml 文件是作为 Content-Type: text.html 发送的吗?有没有办法全局询问 Apache,“如果您要传输为 'text.html',请改用 'text/html'?

谢谢,

小智 5

httpd.conf 或其中一个包含文件中的其他地方可能有一行错误。我会用 grep 检查主要配置和其他配置来跟踪它。

grep Includes httpd.conf
grep text.html httpd.conf
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用 FilesMatch 强制类型。下面是一个例子:

<FilesMatch "\.(shtml)$">
   # type only
   ForceType text/html
   # type and character set
   # ForceType 'text/html; charset=UTF-8'
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)