Speed Up WordPress on IIS Windows WP Super Cache

By Anil Gupta,  10 Jan, 18       10  Tech Tips

Speed up Wordpress on Windows IIS by using URL rewrite rules. Reverse proxy behavior like Squid and Varnish. Fetch WP Super Cache files directly.

It has been some time that I was struggling to speed up WordPress installed on Amazon EC2’s windows server. I did try the W3 Total Cache too before finally settling on WP Super Cache.

If you are running your blog on non-windows i.e. Linux machine, you probably would have already used the in-built features of these cache plug-ins to auto optimize. The problem comes into picture only on windows IIS.

Update: I finally decided to move to Linux for better integration and better server performance for wordpress out of the box. Here is what all i did to move from Amazon EC2 to Google Compute Engine Virtual Machine.

Why WP Cache need special settings on Windows

The simple reason of slow speed is the editing of web.config vs Apache’s htaccess file. By default, the WP Super and W3 Total Cache are designed to automatically edit htaccess file, not the web.config.

I am sure you would have already implemented either of these cache and configured their best settings.
Hence, I am just going to focus primarily on the critical point of jam.

Before we jump to the solution, a little background on how these caches work would help you get a grasp of things.

How do WP Super Cache and W3 Total Cache work?

The way WP Super cache of W3 Total Cache work is that they both create the HTML versions of the posts and the pages.
WP Super cache stores these pages on the disk whereas W3 Total Cache keeps them in the memory.

They then, serve the user requests in the following order:

  1. User requests page www.am22tech.com from the internet browser.
  2. Request reaches your web server and hits IIS. IIS then routes the request to Worpdress PHP engine running in memory. This is a critical junction as it may consume about 1-2 seconds on shared or low memory (RAM) servers.
  3. This time can be saved if the web server can by-pass the wordpress PHP engine completely for the cached pages. By default, both cache plug-ins create the htcaccess file and embed the REWRITE rules to make this happen automatically for you.

    Since, we are on windows server with IIS, the plug-ins are not able to do this automatically for us.
    Hence, whenever we hit the IIS, it has to forward the call to WordPress PHP engine and then the cache plug-ins serve the page either from the disk or memory.

  4. So, the idea is to write these REWRITE rules ourselves in ISS web.config ourselves to completely skip the PHP processing.

Understood the concept? If yes, then here is what you need to do:

  1. Pre-requisite: You would need the URL Rewrite 2.0 extension for IIS. Most probably, you would already have it installed. If not, then please do it now.
  2. Edit the web.config file in your wordpress install. You would find this file in root directory.
  3. Add a new web.config file in the WP Super Cache folder add the Cache-control headers. This is optional but recommended.

IIS Windows WP Super Cache Configuration

  1. I am assuming that you already have WordPress and WP Super Cache plugin installed. If not, then please install it now.
  2. URL rewrite rules required for making WP Super cache work as reverse proxy
    Go to your wordpress root folder and add these in the web.config file. If you do not have already have this file, add a new one.
    <rule name="WP super cache Windows WordPress" 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="{DOCUMENT_ROOT}/wp-content/cache/supercache/{HTTP_HOST}/{R:1}index.html" matchType="IsFile" />
    <action type="Rewrite" url="wp-content/cache/supercache/{HTTP_HOST}/{R:1}index.html" />
  3. (Optional) Create a new web.config file in wp-content\cache folder and add the following rules there. If you do not already have this file there, a add new one.
    <?xml version="1.0" encoding="UTF-8"?>
    <add name="Cache-Control" value="max-age=3000, must-revalidate" />
  4. Save the file and you are all set.

Frequently Asked Questions

Don’t the WP super cache and W3 Total cache have this URL rewrite functions out of the box?
Yes, both of them have it. But, it is only available for Apache web server and not IIS.
They both can create these URL rewrite rules in htcaccess file automatically.

Since you are on windows and most probably using IIS web server, you would need web.config files for the URL rewrite to work.

How to test the speed gains?

You can immediately test the speed gains by using Google Webmasters ‘Fetch like Google’ feature.

Just add any of your post or page link and click fetch. You would see the total time it took Google to fetch that page. It should certainly be much lesser than what it was earlier.
This is simply because IIS is now diverting and serving all incoming calls to the WP Super Cached pages rather than invoking WordPress Engine.
This bypasses WordPress’s PHP engine out of picture completely.

Over a period of 2-3 days to a week, you will start noticing the substantial downfall in the page download time.

Speed gains?

If you believe, the difference was huge. I was able to reduce the page fetch time from 3 seconds to 0.03 seconds. That’s a world of a difference!

Google crawl stats WP super cache reverse proxy windows worpress

Google crawl stats shows the reduction in page load time with WP super cache on windows and worpress

All the posts are now served from the cache directly. WP Super cache works in the background and is never brought into front line processing. PHP engine is never directly touched if you already have a cached file.

PHP log files on windows local machine location

If you are using Microsoft web matrix to develop wordpress, then you can see the PHP log file here:

You can share your suggestions and ask questions, if any in the comments section.

  • I put web.config in wp-contentcache folder but the plugin delete every x times this folder and web.config too

  • Hi Maverick,

    That is fine. The file would be deleted by WP super cache every time it refreshes itself.
    The logic mentioned above will still work as a reverse proxy.

    The web.config inside is only meant to add a cache control header to http response and only aims to have user’s browser cache for 3000 seconds.
    You can ignore the file with no issues.

    Let me know if you need more information.

  • Teejax

    Is the code meant to be added to web.config or create a fresh web.config file with this code?

  • There are 2 web.config required.
    1. In the root folder. If you do not have it already, create a new one here else, add the code in the existing one.
    2. The other web.config is required in wp-contentcache folder. If you do not have one there already, create a new one. Else, add the code to existing one.

    What code is needed in what file is mentioned in above article.
    Let me know if you need more information.

  • Teejax

    I kept getting 500 server error, so I had to deactivate WP Super Cache plugin. Although I have edited the web.config files as you instructed. What could be causing this? I’m using latest WordPress installation on IIS 8

  • 500 server error is a generic error that simply means that there is something wrong in the code files.
    Also, it is possible that the web.config file has some mis-formatted tags.

    There can be multiple reasons for 500 error.

    I would suggest you to type in the code (that provided above) and not simply copy paste.
    Also, are you adding the code above, in your web.config, in the appropriate tag hierarchy?

    if possible, share a screen shot of your web.config and then I can guide.

  • dinesh belakare


    Really thanks for this article.

    But things are not working for me.

    I am using wordpress version 4.2.2 and WP Super Cache Version 1.4.8. Site url is like http://abcd.com/dev/

    I installed this plugin successfully.All files and folders were created automatically. But instead of web.config file .htaccess files were created.

    So I manually created web.config in wordpress root(i.e dev directory) and wp-contents/cache directory and pasted code as you mentioned in article. But still it’s not working.It shows zero in cache contents setting. directory permissions are 777

    Is there anything I am missing?

    Can you help on this ?

    Thank You

  • You should have installed wordpress on WINDOWS machine using Microsoft Web Matrix. That would set up everything for you including web.config in the root.

    Anyways, to make one more check, Is your wordpress running under IIS? IIS is windows web server.
    I am not sure if you have installed Apache or any other web server. If it is NOT IIS, then web.config will not work.

  • I want to install w3 total cache do i need to make same changes in web.config as mentioned for super cache?

  • No changes are needed in W3 Total cache. But, it will not work as reverse proxy engine. W3 total cache’s power would be limited.