Speed up your WordPress Blog on IIS 7 by using WP-Super-Cache
- Since I moved my Blog to an IIS 7 server outside mainland China, I found it became terribly slow than before on a LAMP (Linux+Apache+MySQL+PHP) Server. I tried to find out why my site was so slow running on IIS and wanted to change this situation.
Turning all posts and pages into static html files is a good way to extremely speed up my blog. It is common to install a plugin named “WP-Super-Cahce” for the action. But unfortunately, there was always something wrong in my WP and that plugin doesn’t work at all times. I fixed the problem today and want to share my experience with you all. Let’s start!
If you are a blogger and your blog is based on an IIS 7 environment, I think this article maybe helpful for you. I successfully installed WP-Super-Cache plugin on my IIS 7 website after solving some ugly problems. Let’s make our blog faster and faster runing on Windows Server!
Install and Configure WP-Super-Cache
There are 10 easy steps to get cached content on your IIS or Apache server under Windows:
1. Download plugin.
2. Extract it so you have a /wp-content/plugins/wp-super-cache/ directory with all the files (like wp-cache.php) in there.
3. Copy /wp-content/plugins/wp-super-cache/wp-cache-phase1.php to
/wp-content/advanced-cache.php
4. Open up /wp-content/plugins/wp-super-cache/wp-cache.php and locate this:
[sourcecode language=“php”]function wp_cache_check_link() { global $wp_cache_link, $wp_cache_file;[/sourcecode]
Replace that with [sourcecode language=“php”]function wp_cache_check_link() { global $wp_cache_link, $wp_cache_file; if ( file_exists($wp_cache_link) ) return true; else { echo “advanced-cache.php does not exist”; echo “Create it by copying $wp_cache_file to $wp_cache_link on your server”; return false; } [/sourcecode]
6. Add the following rewrite rule to the web.config file located at the root folder of WordPress site. Make sure that the “WP Super Cache” rule is before the WordPress rule for pretty permalinks. Typically the <rewrite> section will look as below:
<rewrite>
<rules>
<rule name=“WP Super Cache” stopProcessing=“true”>
<match url=”^(\d{4})/(\d{2})/(.+?)/?$” ignoreCase=“false” />
<conditions>
<add input=”{REQUEST_METHOD}” negate=“true” pattern=“POST” ignoreCase=“false” />
<add input=”{QUERY_STRING}” negate=“true” pattern=”.*=.*” ignoreCase=“false” />
<add input=”{QUERY_STRING}” negate=“true”
pattern=”.*attachment_id=.*” ignoreCase=“false” />
<add input=”{HTTP_COOKIE}” negate=“true”
pattern=”^.*(comment_author_|wordpress|wp-postpass_).*$” ignoreCase=“false” />
<add
input=”{DOCUMENT_ROOT}\wp-content\cache\supercache\{HTTP_HOST}\{R:1}\{R:2}\{R:3}\index.html”
matchType=“IsFile” />
</conditions>
<action type=“Rewrite”
url=“wp-content/cache/supercache/{HTTP_HOST}/{R:1}/{R:2}/{R:3}/index.html” />
</rule><rule name=“Wordpress Pretty Permalinks” patternSyntax=“Wildcard”>
<match url=”*” />
<conditions>
<add input=”{REQUEST_FILENAME}” matchType=“IsFile” negate=“true” />
<add input=”{REQUEST_FILENAME}” matchType=“IsDirectory” negate=“true” />
</conditions>
<action type=“Rewrite” url=“index.php” />
</rule>
</rules>
</rewrite>
Note: this rule example is configured to work with WordPress permalinks that use “Month and name” format, e.g. http://wordpress/index.php/2008/12/sample-post/. If you use any other permalink format then the rule will need to be adjusted for that.
If you are using permalink style like “/%post_id%.html”, please use the following configuration:
<rule name=“WP Super Cache” stopProcessing=“true”>
<match url=”^([0–9]+).html$” ignoreCase=“false” />
<conditions>
<add input=”{REQUEST_METHOD}” negate=“true” pattern=“POST” ignoreCase=“false” />
<add input=”{QUERY_STRING}” negate=“true” pattern=”.*=.*” ignoreCase=“false” />
<add input=”{QUERY_STRING}” negate=“true”
pattern=”.*attachment_id=.*” ignoreCase=“false” />
<add input=”{HTTP_COOKIE}” negate=“true”
pattern=”^.*(comment_author_|wordpress|wp-postpass_).*$” ignoreCase=“false” />
<add
input=”{DOCUMENT_ROOT}\wp-content\cache\supercache\{HTTP_HOST}\{R:1}.html\index.html”
matchType=“IsFile” />
</conditions>
<action type=“Rewrite” url=“wp-content/cache/supercache/{HTTP_HOST}/{R:1}.html/index.html” />
</rule>
In addition, if you want to cache your front page like index.php, please add an rule in the front of “WP Super Cache” rule, just like this:
<rule name=“WP Super Cache Index Page” stopProcessing=“true”>
<match url=“index.php” ignoreCase=“false” />
<conditions>
<add input=”{REQUEST_METHOD}” negate=“true” pattern=“POST” ignoreCase=“false” />
<add input=”{QUERY_STRING}” negate=“true” pattern=”.*=.*” ignoreCase=“false” />
<add input=”{QUERY_STRING}” negate=“true”
pattern=”.*attachment_id=.*” ignoreCase=“false” />
<add input=”{HTTP_COOKIE}” negate=“true”
pattern=”^.*(comment_author_|wordpress|wp-postpass_).*$” ignoreCase=“false” />
<add
input=”{DOCUMENT_ROOT}\wp-content\cache\supercache\{HTTP_HOST}\index.html”
matchType=“IsFile” />
</conditions>
<action type=“Rewrite” url=“wp-content/cache/supercache/{HTTP_HOST}/index.html” />
</rule>
7. Add the following line into the wp-config.php file above the “require_once(ABSPATH.’wp-settings.php’);” line:
define( ‘WP_CACHE’, true );
8. Log into your dashboard and enable WP Super Cache in the Plugins page.
9. Go to the WP Super Cache options page and enable caching.
10. If you have mod_gzip, mod_deflate, or IIS dynamic content caching enabled, make sure you don’t enable Super Cache gzip because it’s already being done on the server level (which is better, anyway!
)
After that 10 steps, you may find your blog become faster than before. Please open a post and see the source file code. If that plugin is sucessfully run, you may find the following contents at the bottom of the source code:
<!– Dynamic Page Served (once) in x.xxx seconds –>
If you see that message, Congratulations!
Make it really works for you if you meet extra problems
But in some circumstance, you will get failed. Because some of your plugin prevent WP-Super-Cache from working.
You may see that message instead:
<!– Page not cached by WP Super Cache. No closing HTML tag. Check your theme. –>
Don’t worry about your theme, it may not your theme’s fault. If you’ve seen “</html>” in that source code page, it should be some problems caused by one or more of your other plugins. They may have some conflicts!
For my site, I found my another plugin named StatPressCN is conflicted with WP-Super-Cache. You may try to deactive all your plugins and active them one by one while seeing the html source code to check which plugin is not fit for your WP-Super-Cache. After finding out the conflicts, you can decide which plugin you need more and give up another.
Try to do that and enjoy your faster blog site and your blogger life!
–Paul
Some referrence for my article:
- Getting WordPress Super Cache to Run on a Windows (IIS or Apache) Server
- Speed up WordPress on IIS 7.0
- WP-Super-Cache not Caching

on 2009-12-28 ( Monday ) at 08:44
Permalink
[…] it was not all that fun, and I had to use a number of resources to get it working. Many thanks to Peng-Fei’s blog entry, which got me started, but didn’t quite take me over the finish line. The Wordpress plugin […]