【发布时间】:2016-11-03 14:26:16
【问题描述】:
我的服务器上有两个名为test.html 和test.php 的文件,内容相同:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>TEMPLATE</title>
</head>
<body>
TEXT
</body>
</html>
除此之外,我还有一个 .htaccess-files,其内容如下:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.(php3|php4|php5|php6|html|htm) $1\.php
AddType x-mapp-php5.5 .php
AddHandler x-mapp-php5.5 .php
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
</Ifmodule>
请求test.html 返回以下标头:
Connection: Keep-Alive
Content-Type: text/html
Date: Fri, 01 Jul 2016 08:32:04 GMT
Keep-Alive: timeout=2, max=200
Server: Apache
Transfer-Encoding: chunked
x-powered-by: PHP/5.5.36
取消注释重写部分后(因此使用 HTML 而不经过 PHP 处理),响应头是:
Accept-Ranges: bytes
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 186
Content-Type: text/html
Date: Fri, 01 Jul 2016 08:42:22 GMT
Etag: "xxxxxxxx-xx-xxxxxxxxxxxxx"
Keep-Alive: timeout=2, max=200
Last-Modified: Fri, 01 Jul 2016 08:42:03 GMT
Server: Apache
Vary: Accept-Encoding
内容一模一样,header一模一样,但是为什么PHP返回的时候内容没有被压缩?
【问题讨论】:
-
Apache 不会处理 PHP 输出压缩,因为这是 PHP 的责任。是否启用了 php 输出压缩? (php.net/manual/en/…)
标签: php html .htaccess compression gzip