页面缓存不正确,响应标头似乎错误...如何解决?



好的,我真的不知道如何提出这个问题,但我的问题,或者至少我认为问题是这样的:

我正在处理的博客加载速度非常慢,所以我做了一些正常的事情来加快速度,比如添加gzip和禁用所有插件等等,但这并没有帮助。因此,我查看了Firebug中发送的标题,注意到页面的原始请求花费了很长时间,而其他请求则正常加载。

以下是给定页面的响应/请求标头:

请求标头

Host:               dev.mydomain.com
User-Agent:         Mozilla/5.0... ...Firefox/3.6.17
Accept:             text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language:    en-us,en;q=0.5
Accept-Encoding:    gzip,deflate
Accept-Charset:     ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive:         115
Connection:         keep-alive
Referer:            http://dev.mydomain.com/blog/2011/05/06/hello-world/
Cookie:             Cookie data...

响应标头

Date:               Tue, 07 Jun 2011 17:37:42 GMT
Server:             Apache
X-Pingback:         http://dev.mydomains.com/blog/xmlrpc.php
Expires:            Thu, 19 Nov 1981 08:52:00 GMT
Last-Modified:      Tue, 07 Jun 2011 17:37:59 GMT
Cache-Control:      no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma:             no-cache
Vary:               Accept-Encoding
Content-Encoding:   gzip
Content-Length:     4981
Connection:         close
Content-Type:       text/html; charset=UTF-8

很明显,这里出了问题,因为没有缓存,连接被设置为关闭,过期时间是30年前。

这是我的.htaccess文件,我在其中设置了过期标头等

.htaccess

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/x-javascript
# Or, compress certain file types by extension:
<Files *.html|*.php>
SetOutputFilter DEFLATE
</Files>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/javascript A2592000
FileETag none
AddType text/x-component .htc
AddType image/x-icon .ico 
AddHandler application/x-httpd-php .php .html
DirectoryIndex index.php
allow from all
RewriteEngine on
RewriteBase /  
RewriteCond %{REQUEST_URI} ^/blog/
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ /blog/index.php [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
## Ignore CSS, Scripts and Images
RewriteRule !.(xml|swf|js|ico|gif|jpg|png|css|htc)$ index.php [L]

如有任何帮助,不胜感激。

顺便说一句,我在PHP 5.2.10/MySQL 5.1上运行WordPress 3.1.1

我也在与同样的问题作斗争,我发现你的.htaccess文件只能与你的网络主机提供的权限一样好。你是在主持自己的网站,还是在一家网络托管公司?

如果您正在托管自己的网站,则需要确保"允许覆盖"指令设置正确,以便.htaccess规则正常工作。更好的是,设置httpd.config文件也可以为您完成这项工作。

但是,如果你在一家网络托管公司工作,那么你需要询问他们你可以使用哪些指令(你编写的.htaccess规则)?如果您的网络主机将"允许覆盖"设置为"无",那么您的.htaccess文件将被忽略。

我搜索过的所有地方都表明,在遥远的未来设置Expires标头是最好的:当它设置在过去(1981年11月)时,它会迫使浏览器每次获取一个新的页面/图像。

我建议的最后一件事是仔细检查你的.htaccess规则,这里有一组可能对你有用的起点:

#BEGIN htaccess
#Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
#Protect the htaccess file
<Files wp-config.php>
Order Allow,Deny
Deny from all
</Files>
# Disable directory browsing
Options All -Indexes
# Enable the following of symlinks
Options +FollowSymLinks
<IfModule mod_headers.c>
# No ETags, No Pragma
Header unset Pragma
Header unset ETag
# Make sure proxies deliver correct content
Header append Vary User-Agent env=!dont-vary
# Ensure proxies deliver compressed content correctly
Header append Vary Accept-Encoding
</IfModule>
# Set up Cache Control headers
ExpiresActive On
# Default - Set http header to expire everything 1 week from last access, set must-revalidate
ExpiresDefault A604800
Header append Cache-Control: "max-age=3600, must-revalidate"
# Apply a customized Cache-Control header to frequently-updated files
<FilesMatch "^(test¦eval).html$">
ExpiresDefault A1
Header unset Cache-Control:
Header append Cache-Control: "no-cache, must-revalidate"
</FilesMatch>
<FilesMatch "^robots.txt$">
ExpiresDefault A7200
</FilesMatch>
ExpiresByType image/x-icon A14515200
# Set up caching on media files for 1 month
<FilesMatch ".(gif|jpg|JPG|jpeg|png|PNG|swf)$">
  ExpiresDefault A2419200
</FilesMatch>
# Set up caching on commonly updated files 1 month
<FilesMatch ".(xml|txt|html|js|css)$">
  ExpiresDefault A2419200
</FilesMatch>
<FilesMatch ".(ico|gif|jpg|JPG|jpeg|png|PNG|css|js|html?|xml|txt)$">
FileETag None
</FilesMatch>
<IfModule mod_deflate.c>
<FilesMatch ".(js|css|text|html)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

希望这能有所帮助——祝你好运!

Lightfoot

相关内容

  • 没有找到相关文章

最新更新