Subpages are not cached

In some NGINX, Plesk Onyx and IIS environments, you might notice that the front page of your website is cached by WP Rocket, but the internal pages are not. This can be related to your server setup. 

Why is this happening?

If you are using  Plesk Onyx's suggested configuration file, the one they recommend to use with WordPress in order to enable permalinks, their configuration also adds variables to the $_GET array. The GET array is the one the server creates when query strings like domain.com/?query=string are used in the URLs. 

The same issue can take place for any NGINX and IIS server that is using a similar configuration.

When query strings are present, WP Rocket does not cache those pages by default. This happens, for example, when you access: https://domain.com?nowprocket

In this case, the cache works for the home page because the $_GET array is empty, but when visiting an internal page, the page slug is added to the $_GET array, disabling the cache. 

Fix for Plesk Onyx

The solution is to change the config file.
If you are using Plesk Onyx's suggested configuration for WordPress, you should see something like this:

if (!-e $request_filename) {
	set $test P;
}
	
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
	set $test "${test}C";
}

if ($test = PC) {
	rewrite ^/(.*)$ /index.php?$1;
}

Please change it as follows, and test again:

if (!-e $request_filename){
	rewrite ^(.*)$ /index.php break;
}

If you are not familiar with this kind of configuration, or in case you need assistance, please consult with Plesk support before implementing this.

Fix for IIS servers

In the web.config file, check if the permalinks rewrite rule looks similar to the following:

<rule name="WordPress Permalink Rule" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?page_id={R:0}" />
</rule>

If so, please change it as follows:

<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>

WP Rocket should be able to cache the subpages after making these changes.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.