WP Super Cache won’t cache pages other than home page

In WP Super Cache’s configuration tab “Advance”, it shows:

Add here strings (not a filename) that forces a page not to be cached. For example...

wp-.*\.php
index\.php

And by default (at least for my configuration) WordPress sets Permalink as /index.php/%year%/%monthnum%/%day%/%postname%/. Hence all the posts are “rejected” according to the rule above. Logs confirm this:

00:00:01 10000 /index.php/2019/01/01/... wpcache_do_rebuild: exiting as directory is not a directory: ...
00:00:01 10000 /index.php/2019/01/01/... URI rejected. Not Caching 
00:00:01 10000 /index.php/2019/01/01/... wp_cache_maybe_dynamic: returned $buffer 

It’s possible but not recommended to remove index.php from the reject list for SEO purpose. So I changed Permalink and got a … 404.

For Permalink without index.php to function properly in nginx, It’s necessary to change nginx’s configuration, by adding the following to server section:

location / {
    try_files $uri $uri/ /index.php?$args;
}

After fixing the Permalinks, the pages are cached properly, and can be confirmed by the comments in pages’ source:

<!-- Dynamic page generated in 0.500 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2019-01-19 00:00:00 -->

Leave a Reply

Your email address will not be published. Required fields are marked *