Exclude from cache using URL Strings
-
I am trying to exclude certain pages from being cached.
Under the “Advanced” tab, “Rejected URL Strings”, I have added:
/contact/
/suggest-a-website/
/news-feeds/
/news-feeds/other-news-feeds/But these pages continue to be cached.
How can I set these pages from being cached?
-
It sounds like you’ve taken the right steps, but if those pages are still being cached then something isn’t quite right.
First, may I ask how you are checking if the pages are still cached? The easiest way is to load the pages in an incognito/private browser tab, right click on the page, and select “View Source”. At the bottom of the source code, you will find an HTML comment like the following if the page is cached:
<!-- Cached page generated by WP-Super-Cache on ... -->
Next, let’s double-check the paths. When you load your
contact
page, does it typically have a/
at the end of the URL, or does that get removed?If the
/
is not present at the end of the URL, then you should remove it from your Reject URLs settings. e.g.: just/contact
instead of/contact/
.Finally, have you added each of the paths you want excluded on a line of their own in the rejected URL list?
Hopefully one of these checks will shake out what’s going wrong here.
I use Firefox as my default browser, and use Safari for checking. And the results are the same.
All links on the site end with a slash, “/”, except for the Home page.
Rejected URL Strings:
wp-.*.php
index.php
/contact/
/suggest-a-website/
/news-feeds/
/news-feeds/other-news-feeds/Website: https://thewyoming.net/
Tried removing the trailing slash (/), no change.
Interesting that the browser URL’s have the trailing slash, but in Super Cache > Contents > Fresh WP-Super-Cached Files, the listed links do not have the trailing slash.
Did you clear the cache for those pages after you added them to the “rejected URI” list? If there are cached copies of the pages, they will be served to any visitors.
This functionality stops pages being cached, but won’t stop cached copies being served if they exist.
I just looked at https://thewyoming.net/contact/ and see, for me, the cached copy was made yesterday, but this thread is a week old. If you have “/contact/” rejected, then it shouldn’t have been cached. ??
Do you have any sort of reverse proxy in front of your site that might change the URL seen by WordPress?
If you clear the entire cache, enable the debug log, and then visit the contact page, do you see any warnings the URL is rejected?
You might need to edit wp-cache-phase2.php, and add error_log statements in
wp_cache_is_rejected
to figure out what $uri is when the contact page is loaded, and dump $cache_rejected_uri to the log file too.“Did you clear the cache for those pages after you added them to the “rejected URI” list?” Yes. I confirmed that deleting the cache using Supercache does delete its content from the server. I verified that using FTP. It deletes individual pages I select as well as the entire cache when deleting all.
I have been deleting the said pages from Supercache, testing, and repeating with different settings (ie; with slash, without slash, etc.). So the stamp date would be more recent than when I first posted this thread.
The site is using Nginx, but I have turned that off in cPanel. I purged its entire cache before turning it off and before installing Supercache.
I cleared the cache ran debug and the resulting log I did not, “see any warnings the URL is rejected” – however, that being said, I’m not sure how to read the log.
Thanks for all that information.
I think you’ll have to try adding error_log() statements to
wp_cache_is_rejected
in wp-cache-phase2.php to dump $url and $cache_rejected_uri to your php_error. That will tell you if the $url is somehow not set correctly.“error_log() statements to
wp_cache_is_rejected
in wp-cache-phase2.php to dump $url and $cache_rejected_uri to your php_error”This is a bit above may pay grade – not sure where within the files to place the statements.
OK. Here’s where you can add the logging code. Enable the debug log in the plugin and you’ll see these messages appear when you load one of the rejected pages:
Open up wp-cache-phase2.php in a text editor and at line 1833, the line before theforeach
loop, add this line:wp_cache_debug( "check if $uri is rejected from this list: " . print_r( $cache_rejected_uri, true ) );
Then go a few lines down, and before the
return true
, add this line:wp_cache_debug( "URI rejected by $expr" );
Finally, before
return false
, add this line:wp_cache_debug( "URI was not rejected by list" );
Look for $uri, that it’s the actual page, and not something else. Make sure that the list of rejected pages looks like this:
check if /contact/ is rejected from this list: Array ( [0] => wp-.*\.php [1] => index\.php [2] => /contact/ [3] => /suggest-a-website/ )
Line 1833 does not have foreach ( $cache_rejected_uri as $expr ) {
I’m using the latest version: Version 1.10.0
1829 } 1830 if ( false == is_array( $cache_rejected_uri ) ) { 1831 return false; 1832 } 1833 foreach ( $cache_rejected_uri as $expr ){ 1834 if ( $expr != '' && @preg_match( "~$expr~", $uri ) ) { 1835 return true; 1836 } 1837 } 1838 return false; 1839 }
Would it be possible to send me an edited file, “wp-cache-phase2.php”, for version 1.10.0 that will have the necessary recommended code?
Here’s the entire
wp_cache_is_rejected
function. Replace the one in wp-cache-phase2.php on your site with this code. There are 3 extra wp_cache_debug() calls so enable debugging and look at the debug log.function wp_cache_is_rejected( $uri ) { global $cache_rejected_uri; if ( empty( $uri ) ) { return true; // do not cache if we don't know the URI. } $auto_rejected = array( '/wp-admin/', 'xmlrpc.php', 'wp-app.php' ); foreach ( $auto_rejected as $u ) { if ( strstr( $uri, $u ) ) { return true; // we don't allow caching of wp-admin for security reasons } } if ( false == is_array( $cache_rejected_uri ) ) { return false; } wp_cache_debug( "check if $uri is rejected from this list: " . print_r( $cache_rejected_uri, true ) ); foreach ( $cache_rejected_uri as $expr ) { if ( $expr != '' && @preg_match( "~$expr~", $uri ) ) { wp_cache_debug( "URI rejected by $expr" ); return true; } } wp_cache_debug( "URI was not rejected by list" ); return false; }
Please forgive the lateness of my reply.
Ok, I added the code given, deleted the cached “contact” page, got the debug file, and I’m not sure what I am reading.How can I send you the debug file?
@q120000 – I’m glad you got a debug file out of it! No need to send it to me. Load one of the rejected pages, and look for the
URI rejected by
lines in the debug log:Or look for the
check if $uri is rejected from this list
lines, where $uri is one of your pages. Do you see therejected
message, or the message that says,URI was not rejected by list
?It should look something like this:
check if /contact/ is rejected from this list URI rejected by /contact/
Or if it somehow wasn’t rejected:
check if /contact/ is rejected from this list URI was not rejected by list
Note: I deleted from cache the “contact” page, then ran the debug.
The letters “URI” and “reject” are not even in the debug log.
/contact/ is in the log eleven times.
Here is one part that is in the log: /contact/ ACCEPT: text/html
So, if I am reading this right, the “contact” page is not being rejected, thus it is getting cached.
- The topic ‘Exclude from cache using URL Strings’ is closed to new replies.