做 wordpress行业的站长,肯定绝大部分听过一个缓存的插件,那就是大名顶顶的 wp super cache,它的前身是 wp cache,这个插件来自官方开发人员,更新非常的迅速,在免费插件里面,速度可以说是最快和最完善的,因为你很难再找到比它更适合的或更好的缓存插件。
写这个教程,不是为了像网上其它往上一样再次重复它的配置及操作,那些偶想很多人肯定非常熟悉,所以不再重复日常操作或千篇一律。当然还是要给出 2个前提的步骤,因为这也是偶配置它所需要的过程。下面开始正题。
首先你到官方网站插件里面搜索 wp super cache或打开这个网址,https://wordpress.org/plugins/wp-super-cache 下载版本解压后复制到插件目录进行安装,之后开启缓存功能,类似下图的选项。

更新设置以后继续进入高级选项,勾选启用缓存以便加快访问,缓存方式有3种:如果是Apache的服务器可以选择mod_rewrite模式,其他服务器设置成mod_rewrite的话需要进行一些配置,如果不明白推荐设置成PHP缓存模式,根据下面的说明可以知道,PHP方式也是很快的,类似下图的选项:

通常开启这 2步之后,这个插件就可以正常工作,当然 3种缓存模式随便开启哪种都是可以的,只是在配置及性能上有一定区别,默认的传统缓存现在很少人用了,因为以前虚拟空间时代用得较多,不需要特别的设置和配置就可以使用,现在云主机及独立vps渐渐成为主流,所以一般是选择 php缓存模式或更高级的 mod_rewrite缓存模式。这里详细介绍 mod_rewrite缓存模式,这个模式官方编写时只局限于 apache的 mod_rewrite模式,实际上其它 web服务器一样可以使用这个重写模式,只是需要单独再配置缓存伪静态规则,这也是大部分人从来没有接触过的地方,今天就专门把这块弄清楚。多的不说,下面直接贴出偶的规则,自己写的,根据官方的文档及文件里面的路径,这个会一步一步的解释,至少让人知道它能干些什么和适合哪些场景。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | <!-- BEGIN wp_super_cache --> <rule name="WP_Super_Cache_HTTPS_mobile_gzip" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author|wordpress_logged_in|wp-postpass)_.*$" negate="true"/> <add input="{HTTP_X_WAP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_USER_AGENT}" pattern="^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html.gz" matchType="IsFile"/> </conditions> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/> <set name="HTTP_ACCEPT_ENCODING" value=""/> </serverVariables> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html.gz"/> </rule> <!-- SSL in WordPress: How To Move Your WordPress Site to HTTPS? The Definitive Guide --> <rule name="WP_Super_Cache_HTTPS_mobile" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTP_X_WAP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_USER_AGENT}" pattern="^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" negate="true"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html" matchType="IsFile"/> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html"/> </rule> <rule name="WP_Super_Cache_HTTPS_gzip" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html.gz" matchType="IsFile"/> </conditions> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/> <set name="HTTP_ACCEPT_ENCODING" value=""/> </serverVariables> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html.gz"/> </rule> <rule name="WP_Super_Cache_HTTPS" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" negate="true"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html" matchType="IsFile"/> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html"/> </rule> <!-- This rule must rewrite plug-ins to take effect,because "/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html" overlay index page,please modify "index.html" to "index-http.html". --> <!-- <rule name="WP_Super_Cache_HTTP_gzip" stopProcessing="true"> <match url="^(.*)" ignoreCase="true" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$" /> <add input="{URL}" pattern="^/wp-admin/.*" negate="true" /> <add input="{REQUEST_METHOD}" pattern="POST" negate="true" /> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true" /> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true" /> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" /> <add input="{HTTPS}" pattern="on" negate="true" /> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html.gz" matchType="IsFile" /> </conditions> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" /> <set name="HTTP_ACCEPT_ENCODING" value=""/> </serverVariables> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html.gz" /> </rule> <rule name="WP_Super_Cache_HTTP" stopProcessing="true"> <match url="^(.*)" ignoreCase="true" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$" /> <add input="{URL}" pattern="^/wp-admin/.*" negate="true" /> <add input="{REQUEST_METHOD}" pattern="POST" negate="true" /> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true" /> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true" /> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" negate="true" /> <add input="{HTTPS}" pattern="on" negate="true" /> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html" matchType="IsFile" /> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html" /> </rule> --> <!-- rewrite everything else to WP-Super-Cache's index.html cache file,Unable to jump HTTP to HTTPS after opening,because "/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html" overlay index page,please modify "index.html" to "index-http.html". --> <rule name="WP_Super_Cache_HTTP" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTPS}" pattern="on" negate="true"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html" matchType="IsFile"/> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html"/> </rule> <!-- old wp wuper cache rule. --> <!-- <rule name="wp super cache" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true" /> <add input="{QUERY_STRING}" pattern=".*attachment_id=.*" negate="true" /> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress|wp-postpass_).*$" negate="true" /> <add input="{HTTP_USER_AGENT}" pattern="^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*" negate="true" /> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{HTTP_HOST}/{R:1}index.html" matchType="IsFile" /> </conditions> <action type="Rewrite" url="wp-content/cache/supercache/{HTTP_HOST}/{R:1}index.html" /> </rule> --> <!-- END wp_super_cache --> |
上面的规则偶不想说有多复杂,但它实际上也并不简单,下面逐条来解释其功能。这个规则是倒着写的,也就是写的时候是从最底下开始,因为 web.config是微软的伪静态 iis7.0之后开发的,它里面都是一些逻辑开关及优先级规则,所以一般写伪静态规则时需要从下往上写,最下面的优先级最低,也是排在后面执行,这样才能正确解析网页实际路径或地址功能。
//这条就不解释了,英文写得很清楚,老规则,大概是 2 – 4年前适用的,老版本的插件可以用这条。
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!-- old wp wuper cache rule. --> <!-- <rule name="wp super cache" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true" /> <add input="{QUERY_STRING}" pattern=".*attachment_id=.*" negate="true" /> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress|wp-postpass_).*$" negate="true" /> <add input="{HTTP_USER_AGENT}" pattern="^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).*" negate="true" /> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{HTTP_HOST}/{R:1}index.html" matchType="IsFile" /> </conditions> <action type="Rewrite" url="wp-content/cache/supercache/{HTTP_HOST}/{R:1}index.html" /> </rule> --> |
//这条是最基础的 http index规则,它解析了 wp super cache的正常环境配置下的静态页面地址。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <!-- rewrite everything else to WP-Super-Cache's index.html cache file,Unable to jump HTTP to HTTPS after opening,because "/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html" overlay index page,please modify "index.html" to "index-http.html". --> <rule name="WP_Super_Cache_HTTP" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTPS}" pattern="on" negate="true"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html" matchType="IsFile"/> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html"/> </rule> |
//第 3条是偶自己单独的配置规则,这需要修改当前的插件文件及路径,是专门针对自己空间配置的,你可以省略这段代码的理解,当然也可以细细对比之前第 1条的基础规则,它们之间还是有些关联的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <!-- This rule must rewrite plug-ins to take effect,because "/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index.html" overlay index page,please modify "index.html" to "index-http.html". --> <!-- <rule name="WP_Super_Cache_HTTP_gzip" stopProcessing="true"> <match url="^(.*)" ignoreCase="true" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$" /> <add input="{URL}" pattern="^/wp-admin/.*" negate="true" /> <add input="{REQUEST_METHOD}" pattern="POST" negate="true" /> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true" /> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true" /> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" /> <add input="{HTTPS}" pattern="on" negate="true" /> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html.gz" matchType="IsFile" /> </conditions> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" /> <set name="HTTP_ACCEPT_ENCODING" value=""/> </serverVariables> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html.gz" /> </rule> <rule name="WP_Super_Cache_HTTP" stopProcessing="true"> <match url="^(.*)" ignoreCase="true" /> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$" /> <add input="{URL}" pattern="^/wp-admin/.*" negate="true" /> <add input="{REQUEST_METHOD}" pattern="POST" negate="true" /> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true" /> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true" /> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" negate="true" /> <add input="{HTTPS}" pattern="on" negate="true" /> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html" matchType="IsFile" /> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-http.html" /> </rule> --> |
//下面这 2条就是 https index和 https index gzip规则
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <rule name="WP_Super_Cache_HTTPS_gzip" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html.gz" matchType="IsFile"/> </conditions> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/> <set name="HTTP_ACCEPT_ENCODING" value=""/> </serverVariables> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html.gz"/> </rule> <rule name="WP_Super_Cache_HTTPS" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" negate="true"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html" matchType="IsFile"/> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https.html"/> </rule> |
//第 5条也是最后一条,是手机浏览器下面使用的mobile-https index和它的压缩规则。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <rule name="WP_Super_Cache_HTTPS_mobile_gzip" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author|wordpress_logged_in|wp-postpass)_.*$" negate="true"/> <add input="{HTTP_X_WAP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_USER_AGENT}" pattern="^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html.gz" matchType="IsFile"/> </conditions> <serverVariables> <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/> <set name="HTTP_ACCEPT_ENCODING" value=""/> </serverVariables> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html.gz"/> </rule> <!-- SSL in WordPress: How To Move Your WordPress Site to HTTPS? The Definitive Guide --> <rule name="WP_Super_Cache_HTTPS_mobile" stopProcessing="true"> <match url="^(.*)" ignoreCase="true"/> <conditions logicalGrouping="MatchAll"> <add input="{URL}" pattern="^(.*)$"/> <add input="{URL}" pattern="^/wp-admin/.*" negate="true"/> <add input="{REQUEST_METHOD}" pattern="POST" negate="true"/> <add input="{QUERY_STRING}" pattern=".*=.*" negate="true"/> <add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$" negate="true"/> <add input="{HTTP_X_WAP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_PROFILE}" pattern="^[a-z0-9\"]+"/> <add input="{HTTP_USER_AGENT}" pattern="^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).*"/> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" negate="true"/> <add input="{HTTPS}" pattern="on"/> <add input="{DOCUMENT_ROOT}/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html" matchType="IsFile"/> </conditions> <action type="Rewrite" url="/wp-content/cache/supercache/{SERVER_NAME}/{R:1}/index-https-mobile.html"/> </rule> |
虽然就这么几条规则,但却能够省却大量的服务端数据库查询工作,当清空全部缓存之后第 1次访问时正常生成静态页面(及压缩gzip文件)及路径,然后第 2次之后访问就都是由 web.config来解析到静态页面的地址,这就减少了大量的数据库读取的工作,也就加快了访问网站前台页面的速度。不得不说 wp super cache是个非常好的缓存插件,至少它是目前免费版本里面最突出的,相信有了这些规则之后,你也再不需要去研究或寻找关于 iis7.5及以上 web.config规则了。