分享我的 wordpress htaccess 设置

  [复制链接]
查看: 650   回复: 11
发表于 2013-5-26 09:37:22 | 显示全部楼层 |阅读模式
本帖最后由 pootor 于 2013-5-26 09:37 编辑

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

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

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

  4. # BEGIN leverage-browser-caching
  5. <IfModule mod_expires.c>
  6. ExpiresActive on
  7. # Perhaps better to whitelist expires rules? Perhaps.
  8. ExpiresDefault      "access plus 1 month"
  9. # cache.appcache needs re-requests
  10. # in FF 3.6 (thx Remy ~Introducing HTML5)
  11. ExpiresByType text/cache-manifest "access plus 0 seconds"
  12. # Your document html
  13. ExpiresByType text/html "access plus 0 seconds"
  14. # Data
  15. ExpiresByType text/xml "access plus 0 seconds"
  16. ExpiresByType application/xml "access plus 0 seconds"
  17. ExpiresByType application/json "access plus 0 seconds"
  18. # RSS feed
  19. ExpiresByType application/rss+xml "access plus 1 hour"
  20. # Favicon (cannot be renamed)
  21. ExpiresByType image/x-icon "access plus 1 week"
  22. # Media: images, video, audio
  23. ExpiresByType image/gif "access plus 1 month"
  24. ExpiresByType image/png "access plus 1 month"
  25. ExpiresByType image/jpg "access plus 1 month"
  26. ExpiresByType image/jpeg "access plus 1 month"
  27. ExpiresByType video/ogg "access plus 1 month"
  28. ExpiresByType audio/ogg "access plus 1 month"
  29. ExpiresByType video/mp4 "access plus 1 month"
  30. ExpiresByType video/webm "access plus 1 month"
  31. # HTC files  (css3pie)
  32. ExpiresByType text/x-component "access plus 1 month"
  33. # Webfonts
  34. ExpiresByType font/truetype "access plus 1 month"
  35. ExpiresByType font/opentype "access plus 1 month"
  36. ExpiresByType application/x-font-woff   "access plus 1 month"
  37. ExpiresByType image/svg+xml "access plus 1 month"
  38. ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  39. # CSS and JavaScript
  40. ExpiresByType text/css "access plus 1 year"
  41. ExpiresByType application/javascript "access plus 1 year"
  42. ExpiresByType text/javascript "access plus 1 year"
  43. <IfModule mod_headers.c>
  44.   Header append Cache-Control "public"
  45. </IfModule>
  46. </IfModule>
  47. # END leverage-browser-caching
复制代码

评分

参与人数 2T币 +4 收起 理由
心若无尘 + 3 有見地
dealer + 1 谢谢分享!

查看全部评分

发表于 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/ 修改的

  1. Header unset ETag
  2. FileETag None
  3. <ifModule mod_deflate.c>
  4.         AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
  5. </ifModule>
  6. <ifModule mod_expires.c>
  7.         ExpiresActive On
  8.         ExpiresDefault "access plus 5 seconds"
  9.         ExpiresByType image/x-icon "access plus 2592000 seconds"
  10.         ExpiresByType image/jpeg "access plus 2592000 seconds"
  11.         ExpiresByType image/png "access plus 2592000 seconds"
  12.         ExpiresByType image/gif "access plus 2592000 seconds"
  13.         ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  14.         ExpiresByType text/css "access plus 604800 seconds"
  15.         ExpiresByType text/javascript "access plus 216000 seconds"
  16.         ExpiresByType application/javascript "access plus 216000 seconds"
  17.         ExpiresByType application/x-javascript "access plus 216000 seconds"
  18.         ExpiresByType text/html "access plus 600 seconds"
  19.         ExpiresByType application/xhtml+xml "access plus 600 seconds"
  20. </ifModule>
  21. <ifModule mod_headers.c>
  22.         <filesMatch "\.(ico|jpe?g|png|gif|swf)[        DISCUZ_CODE_0        ]quot;>
  23.                 Header set Cache-Control "public"
  24.         </filesMatch>
  25.         <filesMatch "\.(css)[        DISCUZ_CODE_0        ]quot;>
  26.                 Header set Cache-Control "public"
  27.         </filesMatch>
  28.         <filesMatch "\.(js)[        DISCUZ_CODE_0        ]quot;>
  29.                 Header set Cache-Control "private"
  30.         </filesMatch>
  31.         <filesMatch "\.(x?html?|php)[        DISCUZ_CODE_0        ]quot;>
  32.                 Header set Cache-Control "private, must-revalidate"
  33.         </filesMatch>
  34. </ifModule>
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-5-26 11:43:21 | 显示全部楼层
这些都有什么功能呢?好像是缓存设置吧?装个缓存插件就搞定了吧
回复 支持 反对

使用道具 举报

发表于 2013-5-26 13:22:12 | 显示全部楼层
是首页静态化吗
回复 支持 反对

使用道具 举报

发表于 2013-5-26 13:52:38 | 显示全部楼层
先收下
回复 支持 反对

使用道具 举报

发表于 2013-5-26 16:45:18 | 显示全部楼层
这个起什么作用
回复 支持 反对

使用道具 举报

发表于 2013-5-26 17:12:42 | 显示全部楼层
不错,学习了。。。
回复 支持 反对

使用道具 举报

发表于 2013-5-26 20:15:34 | 显示全部楼层
.....给简单解释下呗~~~~~~~~~~~
回复 支持 反对

使用道具 举报

发表于 2013-5-26 21:26:32 | 显示全部楼层
感谢分享
回复 支持 反对

使用道具 举报

发表于 2013-5-28 21:48:50 | 显示全部楼层
相当专业的东西,看不懂
回复 支持 反对

使用道具 举报

发表于 2013-5-28 21:59:30 | 显示全部楼层
分享我的 wordpress htaccess 设置看得不是很懂..
回复 支持 反对

使用道具 举报

发表于 2013-5-29 21:56:54 | 显示全部楼层
我用的是WP-Optimize插件,里面有一些比较好的功能!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则