{"id":227,"date":"2016-12-09T09:35:05","date_gmt":"2016-12-09T01:35:05","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=227"},"modified":"2016-12-09T09:35:05","modified_gmt":"2016-12-09T01:35:05","slug":"htaccess%e6%96%b9%e5%bc%8f%e5%90%af%e7%94%a8gzip%e5%8e%8b%e7%bc%a9css%e5%92%8cjs","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=227","title":{"rendered":"htaccess\u65b9\u5f0f\u542f\u7528gzip\u538b\u7f29CSS\u548cJS"},"content":{"rendered":"<p>\u538b\u7f29WordPress\u7f51\u9875gzip\u63d2\u4ef6\u6709\u5f88\u591a\uff0c\u524d\u9762\u4e00\u7bc7\u6587\u7ae0\u7684GZippy\u5c31\u53ef\u4ee5\uff0c\u538b\u7f29CSS\u548cJS\u6210\u4e3agzip\u7684\u63d2\u4ef6\u4e5f\u662f\u6709\u7684\uff0c\u4e0d\u8fc7\u4e0b\u9762\u63d0\u4f9b\u4e00\u79cdhtaccess\u9759\u6001\u624b\u5de5\u538b\u7f29\u7684\u529e\u6cd5\uff0c\u6709\u4e9b\u9ebb\u70e6\u4f46\u8d85\u7ea7\u9ad8\u6548\uff0c\u800c\u4e14\u517c\u5bb9\u6027\u597d\uff0c\u4e0d\u9650\u4e8eWordPress\u7f51\u7ad9\u3002<\/p>\n<p>1.\u4e0b\u8f7d<a href=\"http:\/\/ishare.iask.sina.com.cn\/f\/12128746.html\" target=\"_blank\" rel=\"nofollow\">Gzip.rar<\/a>\u6587\u4ef6\uff0c\u89e3\u538b\u540e\u5c06Gzip.php\u6587\u4ef6\u4e0a\u4f20\u5230\u7f51\u7ad9\u7684\u6839\u76ee\u5f55\u4e0b\uff0c\u4e5f\u5c31\u662f\/public_html\/\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p>2.\u4fee\u6539\u7f51\u7ad9\u7684.htaccess\u6587\u4ef6\uff0c\u5728\u5176\u4e2d\u589e\u6dfb\u5982\u4e0b\u8bed\u53e5\uff1a<\/p>\n<blockquote><p>#\u8fa8\u8bc6gz\u6863\u6848\u7684\u652f\u6301<br \/>\n&lt;Files *.js.gz&gt;<br \/>\nAddEncoding gzip .js<br \/>\nForceType application\/x-javascript<br \/>\n&lt;\/Files&gt;<br \/>\n&lt;Files *.css.gz&gt;<br \/>\nAddEncoding gzip .css<br \/>\nForceType text\/css<br \/>\n&lt;\/Files&gt;<\/p>\n<p>&lt;IfModule mod_rewrite.c&gt;<br \/>\nRewriteEngine On<br \/>\nRewriteBase \/<\/p>\n<p>#wordpress\u9759\u6001\u7f51\u5740\u7684\u652f\u6301\uff0c\u5982\u679c\u4f60\u8bbe\u7f6e\u7684\u8bdd\u4f1a\u6709\u5982\u4e0b\u4e09\u884c<br \/>\nRewriteCond %{REQUEST_FILENAME} !-f<br \/>\nRewriteCond %{REQUEST_FILENAME} !-d<br \/>\nRewriteRule . \/index.php [L]<\/p>\n<p>#\u8bfb\u5230css\u548cjs\uff0c\u5c31\u91cd\u5bfc\u81f3gzip.php<br \/>\nRewriteRule (.*.css$|.*.js$) gzip.php?$1 [L]<\/p>\n<p>#\u8bfb\u5230.css\uff0c\u5224\u65ad\u5982\u679c\u6d4f\u89c8\u5668\u652f\u6301gzip\u4e14.css.gz\u5b58\u5728\uff0c\u5c31\u8fdb\u884c\u91cd\u5bfc<br \/>\nRewriteCond %{HTTP:Accept-encoding} gzip<br \/>\nRewriteCond %{REQUEST_FILENAME}.gz -f<br \/>\nRewriteRule ^(.*).css $1.css.gz [L,QSA]<\/p>\n<p>#\u8bfb\u5230.js\uff0c\u5224\u65ad\u5982\u679c\u6d4f\u89c8\u5668\u652f\u6301gzip\u4e14.js.gz\u5b58\u5728\uff0c\u5c31\u8fdb\u884c\u91cd\u5bfc<br \/>\nRewriteCond %{HTTP:Accept-encoding} gzip<br \/>\nRewriteCond %{REQUEST_FILENAME}.gz -f<br \/>\nRewriteRule ^(.*).js $1.js.gz [L,QSA]<br \/>\n&lt;\/IfModule&gt;<\/p><\/blockquote>\n<p>3.\u6d4f\u89c8\u81ea\u5df1\u7684\u7f51\u7ad9\uff0c\u8ba9CSS\u548cJS\u4ea7\u751fgz\u6863\uff1b\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u53d1\u73b0\u6d4f \u89c8\u8fc7\u540e\uff0cCSS\u548cJS\u6587\u4ef6\u6ca1\u6709\u4ea7\u751fgz\u6587\u4ef6\uff0c\u8bf7\u6ce8\u610f\u628aCSS\u548cJS\u6240\u5728\u6587\u4ef6\u5939\u7684\u4e0a\u5c42\u6587\u4ef6\u5939\u5c5e\u6027\u4fee\u6539\u4e3a777<\/p>\n<p>4.\u6700\u540e\uff0c\u518d\u6b21\u6539\u5199.htaccess\uff0c\u628a\u4ee5\u4e0b\u4ee3\u7801\u6ce8\u91ca\u6389\u6216\u5220\u9664\u3002<\/p>\n<blockquote><p>RewriteRule (.*.css$|.*.js$) gzip.php?$1 [L]<\/p><\/blockquote>\n<p>\u6ce8\u610f\uff1a\u5982\u679c\u4ee5\u540e\u8981\u4fee\u6539CSS\u548cJS\uff0c\u90a3\u8fd8\u8981\u8fd8\u539f\u90a3\u53e5\u4ee3\u7801\u5e76\u91cd\u505a\u7b2c3\u30014\u6b65\u3002<\/p>\n<p>\u65b9\u6cd5\u6709\u4e9b\u9ebb\u70e6\uff0c\u4e0d\u8fc7\u6548\u679c\u5f88\u597d\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u51e0\u4e2a\u6d4b\u8bd5\u7f51\u7ad9\u662f\u5426\u542f\u7528gzip\u538b\u7f29\u7684\u7f51\u5740\uff1a<br \/>\n<a href=\"http:\/\/tool.chinaz.com\/Gzips\/Default.aspx\" target=\"_blank\" rel=\"nofollow\">http:\/\/tool.chinaz.com\/Gzips\/Default.aspx<\/a><\/p>\n<p><a href=\"http:\/\/gzip.zzbaike.com\/\" target=\"_blank\" rel=\"nofollow\">http:\/\/gzip.zzbaike.com\/<\/a><\/p>\n<p><a href=\"http:\/\/www.websiteoptimization.com\/services\/analyze\/\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.websiteoptimization.com\/services\/analyze\/<\/a><\/p>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u538b\u7f29WordPress\u7f51\u9875gzip\u63d2\u4ef6\u6709\u5f88\u591a\uff0c\u524d\u9762\u4e00\u7bc7\u6587\u7ae0\u7684GZippy\u5c31\u53ef\u4ee5\uff0c&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=227\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-227","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227"}],"version-history":[{"count":1,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions"}],"predecessor-version":[{"id":228,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions\/228"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}