HTTP缓存无法正常工作

时间:2014-02-07 12:31:50

标签: php .htaccess caching

我相信我做的一切都是正确的,但由于某种原因,我的HTTP缓存无法运行。首先,我检查了mod_headers和mod_expires是否为我的服务器启用了修改。我通过在SSH中运行以下命令来完成此操作:

sudo apachectl -M

两个模块都列在“已加载模块”下,因此应启用它们。接下来,我在.htaccess文件中添加了正确的代码,导致.htaccess看起来像这样:

# 1 DAY
<FilesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=86400, public"
</FilesMatch>

# 1 MONTH
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2630000, public"
</FilesMatch>

Options -Indexes

RewriteEngine On
# turn on the mod_rewrite engine

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME}.php -f
# IF the request filename with .php extension is a file which exists
RewriteCond %{REQUEST_URI} !/$
# AND the request is not for a directory
RewriteRule (.*) $1\.php [L]
# redirect to the php script with the requested filename

SetEnv PHPRC /home/mywebsitename/public_html/

如果我没弄错,现在应该将.php页面缓存1天,将.jpg文件缓存1个月。但是,我主页上的一些内容是动态的,当我第二次访问该页面时,它会显示不同的内容。这让我相信页面没有从缓存中加载?

有什么想法? (我想在.htaccess中设置它,而不是直接在我的配置文件中设置)

编辑:REDbot输出如下:

HTTP/1.1 200 OK
    Date: Fri, 07 Feb 2014 12:47:27 GMT
    Server: Apache/2.2.26 (Unix) mod_ssl/2.2.26 OpenSSL/1.0.1e-fips
        mod_auth_passthrough/2.1 mod_bwlimited/1.4
        FrontPage/5.0.2.2635
    X-Powered-By: PHP/5.4.24
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
        check=0
    Pragma: no-cache
    Set-Cookie: PHPSESSID=7831fa506c0af85ad99c2673a37b6612; path=/
    Cache-Control: max-age=86400, public
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/html

0 个答案:

没有答案