Title: Exclude from cache using URL Strings
Last modified: August 8, 2023

---

# Exclude from cache using URL Strings

 *  Resolved [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/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?

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/page/2/?output_format=md)

 *  Plugin Contributor [Mark (a11n)](https://wordpress.org/support/users/thingalon/)
 * (@thingalon)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16972986)
 * 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:
 *     ```wp-block-code
       <!-- 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.
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16975719)
 * 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/](https://thewyoming.net/)
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16975726)
 * 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.
 *  Plugin Author [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * (@donncha)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16976385)
 * 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.
 *  Plugin Author [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * (@donncha)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16976416)
 * I just looked at [https://thewyoming.net/contact/](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.
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16978336)
 * “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.
 *  Plugin Author [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * (@donncha)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16980246)
 * 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.
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16981888)
 * “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.
 *  Plugin Author [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * (@donncha)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16994371)
 * 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
   the `foreach` 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:
 *     ```wp-block-code
       check if /contact/ is rejected from this list: Array
       (
       [0] => wp-.*\.php
       [1] => index\.php
       [2] => /contact/
       [3] => /suggest-a-website/
       ) 
       ```
   
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16996933)
 * Line 1833 does not have foreach ( $cache_rejected_uri as $expr ) {
 * I’m using the latest version: Version 1.10.0
 *     ```wp-block-code
       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	}
       ```
   
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16996934)
 * 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?
 *  Plugin Author [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * (@donncha)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-16997254)
 * 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.
 *     ```wp-block-code
       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;
       }
       ```
   
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-17011025)
 * 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?
 *  Plugin Author [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * (@donncha)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-17014747)
 * [@q120000](https://wordpress.org/support/users/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 the `rejected` message, or the message that 
   says, `URI was not rejected by list`?
 * It should look something like this:
 *     ```wp-block-code
       check if /contact/ is rejected from this list
       URI rejected by /contact/
       ```
   
 * Or if it somehow wasn’t rejected:
 *     ```wp-block-code
       check if /contact/ is rejected from this list
       URI was not rejected by list
       ```
   
 *  Thread Starter [q120000](https://wordpress.org/support/users/q120000/)
 * (@q120000)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/#post-17016087)
 * 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/htmlSo, if 
   I am reading this right, the “contact” page is not being rejected, thus it is
   getting cached.

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/page/2/?output_format=md)

The topic ‘Exclude from cache using URL Strings’ is closed to new replies.

 * ![](https://ps.w.org/wp-super-cache/assets/icon-256x256.png?rev=3506220)
 * [WP Super Cache](https://wordpress.org/plugins/wp-super-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-super-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-super-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-super-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-super-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-super-cache/reviews/)

 * 26 replies
 * 3 participants
 * Last reply from: [Donncha O Caoimh (a11n)](https://wordpress.org/support/users/donncha/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/exclude-from-cache-using-url-strings/page/2/#post-17031321)
 * Status: resolved