Ok, I really didn't know how to put the question but my problem or at least I think it's the problem goes like this:
The blog I am working on loads really slow and so I did the normal things to speed it up such as add gzip and disabled all plug-ins etc. and it didn't help. So I looked at the headers being sent in Firebug and noticed the original request for the page was taking forever while the rest of the requests loaded as normal.
Here's the response/reque开发者_如何学Pythonst headers for a given page:
Request Headers
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...
Response Headers
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
Obviously something is wrong here as there's no cache, connection is set to close and the expires is 30 years ago.
Here's my .htaccess file where I set my expires header etc.
.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]
Any help if much appreciated.
BTW, I'm running WordPress 3.1.1 on PHP 5.2.10/MySQL 5.1 on CentOS 5.*
I am battling with the same issues and one thing I discovered is that your .htaccess file is only as good as the permissions given by your web host. Are you hosting your own website or are you with a webhosting company?
If you are hosting your own site you need to make sure that the 'Allow Override' directive is set properly so the .htaccess rules will work. Better yet, set up the httpd.config file to do the job for you as well.
But if you are with a webhosting company, then you need to ask them about which directives (those .htaccess rules you wrote) you can use? If your webhost has the Allow Override set to NONE, then your .htaccess file will be ignored.
Everywhere I have searched states that an Expires header set in the far future is best: when it's set in the past (Nov 1981) it forces the browser to fetch a new page/image each time.
The last thing I would suggest is to double check your .htaccess rules, here is a set that might be useful to you as a starting point:
#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>
Hope this has been of some help--Good Luck!
Lightfoot
精彩评论