pootor 发表于 2013-5-26 09:37:22

分享我的 wordpress htaccess 设置

本帖最后由 pootor 于 2013-5-26 09:37 编辑

把下面的代码复制,添加到你网站根目录的.htaccess里面去(某些主机可能需要打开隐藏文件显示)。

都有解释,应该通用,如果你经常改 css 文件,可以把 css哪行的缓存时间设短点。

用了这个,速度会有所提升,我只能帮你这些了# BEGIN Configure entity tags
FileETag none
# END Configure entity tags

# BEGIN leverage-browser-caching
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault      "access plus 1 month"
# cache.appcache needs re-requests
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files(css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff   "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
# END leverage-browser-caching

luguokankan 发表于 2013-5-26 09:54:50

本帖最后由 luguokankan 于 2013-5-26 10:01 编辑

基于http://wp.tutsplus.com/tutorials/hosting/optimizing-wordpress-loading-speed-with-header-php-htaccess/ 修改的
Header unset ETag
FileETag None
<ifModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
<ifModule mod_expires.c>
      ExpiresActive On
      ExpiresDefault "access plus 5 seconds"
      ExpiresByType image/x-icon "access plus 2592000 seconds"
      ExpiresByType image/jpeg "access plus 2592000 seconds"
      ExpiresByType image/png "access plus 2592000 seconds"
      ExpiresByType image/gif "access plus 2592000 seconds"
      ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
      ExpiresByType text/css "access plus 604800 seconds"
      ExpiresByType text/javascript "access plus 216000 seconds"
      ExpiresByType application/javascript "access plus 216000 seconds"
      ExpiresByType application/x-javascript "access plus 216000 seconds"
      ExpiresByType text/html "access plus 600 seconds"
      ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
<ifModule mod_headers.c>
      <filesMatch "\.(ico|jpe?g|png|gif|swf)[      DISCUZ_CODE_0      ]quot;>
                Header set Cache-Control "public"
      </filesMatch>
      <filesMatch "\.(css)[      DISCUZ_CODE_0      ]quot;>
                Header set Cache-Control "public"
      </filesMatch>
      <filesMatch "\.(js)[      DISCUZ_CODE_0      ]quot;>
                Header set Cache-Control "private"
      </filesMatch>
      <filesMatch "\.(x?html?|php)[      DISCUZ_CODE_0      ]quot;>
                Header set Cache-Control "private, must-revalidate"
      </filesMatch>
</ifModule>

dhdz187 发表于 2013-5-26 11:43:21

这些都有什么功能呢?好像是缓存设置吧?装个缓存插件就搞定了吧

wawylysys 发表于 2013-5-26 13:22:12

是首页静态化吗

dealer 发表于 2013-5-26 13:52:38

先收下

bjghw 发表于 2013-5-26 16:45:18

这个起什么作用

知行合一 发表于 2013-5-26 17:12:42

不错,学习了。。。

嗯嗯 发表于 2013-5-26 20:15:34

.....给简单解释下呗~~~~~~~~~~~

自由的狼 发表于 2013-5-26 21:26:32

感谢分享

gxlm2001 发表于 2013-5-28 21:48:50

相当专业的东西,看不懂

fantasy163 发表于 2013-5-28 21:59:30

:L看得不是很懂..

蒙毅出世 发表于 2013-5-29 21:56:54

我用的是WP-Optimize插件,里面有一些比较好的功能!
页: [1]
查看完整版本: 分享我的 wordpress htaccess 设置