Title: Help with path-based rules
Last modified: July 1, 2020

---

# Help with path-based rules

 *  Resolved [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/)
 * Hi,
 * We have a very custom WP website that uses AO + CriticalCSS powerup (website 
   is [http://www.goodhire.com](http://www.goodhire.com)).
 * The problem is that the website does not properly register 404s. So every request
   to a page that does not exist generates its own custom path-based CCSS rule. 
   Eventually this breaks the user interface for the CCSS powerup.
 * We have created a pretty extensive “Add CSS to all rules” CSS that covers most
   pages. Can we create a manual path-based rule using that CSS that would basically
   apply to every page on the website, thus stopping the creation of all of these
   unnecessary path-based rules?
 * Or alternatively, can I use the “Edit Default Rule CSS” to prevent new path-based
   rules from being created?
 * Thank you,
    Ben

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

1 [2](https://wordpress.org/support/topic/help-with-path-based-rules/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/help-with-path-based-rules/page/2/?output_format=md)

 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13060625)
 * that’s a hard one Ben … my first advise would be to find the reason why the 404’
   s aren’t recognized as such, this really is a major bug imho.
 * if that is not possible; would the resulting not-404 page use one specific template
   that you could target with a manual rule maybe? if not: might that page have 
   specific/ unique text which we could try writing some code against?
 * frank
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13060667)
 * Hi Frank,
 * The page does have specific text. How would that work? Here’s what it looks like:
   [https://www.goodhire.com/this-should-be-a-404/](https://www.goodhire.com/this-should-be-a-404/).
   There’s plenty of unique text on that page.
 * Also, is there a filter to turn off just critical css for pages, but keep the
   rest of AO’s optimization in effect?
 * Thanks,
    Ben
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13063549)
 * OK, so based on the attributes of the body tag the post ID of that page is 1761;
 * `<body class="page-template-default page page-id-1761 patterns-404 is-404 header-
   default footer-default">`
 * Now the code snippet I had in mind won’t work, because that would stop CCSS being
   added to the page, while we need to stop enqueing, so [I just added a new filter to what will become 2.7.4](https://github.com/futtta/autoptimize/commit/bd0f16ae8fe936fc3b7425dde54900900e470fcd)
   somewhere next week.
 * With that change and the page ID of your non-404 404 page, below code (or something
   very similar) should stop that from being enqueued (fingers crossed);
 *     ```
       add_filter( 'autoptimize_filter_ccss_enqueue_should_enqueue', 'fake_not_found_handler' );
       function fake_not_found_handler() {
           $id = get_the_ID();
           if ( $id == 1761 ) {
               return false;
           }
           return true;
       }
       ```
   
 * Would be great if you could [download the beta](https://github.com/futtta/autoptimize/archive/beta.zip)
   and test all of that 🙂
 * frank
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13064632)
 * Hi Frank,
 * Thanks so much! I will test the beta.
 * Ben
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13065163)
 * Hi Frank,
 * This appears to work in a testing environment. Thank you!
 * Possibly related question: We have been getting occasional 404s on the autoptimize
   CSS file on our live environment (using 2.6 of the plugin). The file that looks
   like /wp-content/uploads/autoptimize/css/autoptimize_f9b0a33f8bf23b5649f1d3bfec0c2595.
   css
 * As a result, several important page components are not being displayed. Do you
   know why there might be a 404 on that CSS file? Could it be related to there 
   being hundreds of rules, and somehow the function timing out or some sort of 
   backend failure?
 * Thank you,
    Ben
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13065172)
 * there is no link between critical CSS rules (which result in inlined CSS) and
   missing autoptimized files (which are deferred full CSS-files).
 * maybe just switch to 2.7.3 (soon 4) and tick that “404 fallback” option?
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13065422)
 * Hi Frank,
 * Yes we are going to update asap.
 * What 404 fallback option? I don’t see any option like that in the AO CCSS settings.
 * Thanks,
    Ben
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13066386)
 * 404 fallback is on the main AO settings screen, near the bottom 🙂
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13106870)
 * Hi Frank,
 * That “don’t enqueue CCSS” filter does not appear to work, actually. I’m using
   2.4 beta-1. I’ve got this snippet active:
 *     ```
       add_filter( 'autoptimize_filter_ccss_enqueue_should_enqueue', 'custom_404_page_handler' );
       function custom_404_page_handler() {
           $id = get_the_ID();
           if ( $id == 1761 ) {
               return false;
           }
           return true;
       }
       ```
   
 * However, URLs that are 404s keep showing up in the CCSS queue. Is it possible
   get_the_id() runs before the id is set to 1761?
 * Thanks,
    Ben
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13107035)
 * only one way to find out; do some `error_log()`-ing?
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13127405)
 * Hi Frank,
 * Our site went down last night for several hours, probably related to CCSS and
   the fact that the site does not properly register 404s. I was hoping you could
   give any advice you have on this. It’s hosted on Pantheon. It started generating
   thousands of PHP errors like the one below. Basically a DB query was blocking
   all others:
 * [15-Jul-2020 06:50:07 UTC] WordPress database error Error writing file ‘/srv/
   bindings/ee304d1e67094318b1ef1a816fb052f8/tmp/MLmOc4lH’ (Errcode: 122 Internal(
   unspecified) error in handler”) for query UPDATE `wp_options` SET `option_value`
   = ‘{\”\\/cookie-policy\\/10\\/filemanager\ css no longer exists. Please re-generate
   it.\”,\”jvstat\”:\”NONE\”,\”jctime\”:1594769778.188958,\”jftime\”:1594784935.664043},\”\\/
   get-started\\/about-you\\/2012\\/connect.inc\”:{\”ljid\”:\”j-01nz95\”,\”rtarget\”:\”
   paths|\\/get-started\\/about-you\\/2012\\/connect.inc\”,\”ptype\”:\”is_page\”,\”
   hashes\”:[\”1b0c4f81aaf64425d051d4db974c1797\”],\”hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”
   file\”:null,\”jid\”:\”53717188YE4-iDyZeG\”,\”jqstat\”:\”NO_CSS\”,\”jrstat\”:\”
   This css no longer exists. Please re-generate it.\”,\”jvstat\”:\”NONE\”,\”jctime\”:
   1594782462.385082,\”jftime\”:1594784946.826488},\”\\/industry\\/healthcare\\/
   healthcare.7z\”:{\”ljid\”:\”j-00tc32\”,\”rtarget\”:\”paths|\\/industry\\/healthcare\\/
   healthcare.7z\”,\”ptype\”:\”is_page\”,\”hashes\”:[\”1b0c4f81aaf64425d051d4db974c1797\”],\”
   hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”file\”:null,\”jid\”:\”53689580uVbMLIoPtt\”,\”
   jqstat\”:\”JOB_UNKNOWN\”,\”jrstat\”:\”NONE\”,\”jvstat\”:\”NONE\”,\”jctime\”:1594754891.664372,\”
   jftime\”:1594757934.593131},\”\\/security\\/Admin\”:{\”ljid\”:\”j-015s2b\”,\”
   rtarget\”:\”paths|\\/security\\/Admin\”,\”ptype\”:\”is_page\”,\”hashes\”:[\”1b0c4f81aaf64425d051d4db974c1797\”],\”
   hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”file\”:null,\”jid\”:\”53689596JvXFjTknSn\”,\”
   jqstat\”:\”JOB_UNKNOWN\”,\”jrstat\”:\”NONE\”,\”jvstat\”:\”NONE\”,\”jctime\”:1594753055.52792,\”
   jftime\”:1594757945.080542},\”\\/screening\\/drug-testing\\/developers\”:{\”ljid\”:\”
   j-03l3ov\”,\”rtarget\”:\”paths|\\/screening\\/drug-testing\\/developers\”,\”ptype\”:\”
   is_page\”,\”hashes\”:[\”8f069fc40d15c90411e55506fe7c7fa9\”],\”hash\”:\”8f069fc40d15c90411e55506fe7c7fa9\”,\”
   file\”:null,\”jid\”:\”53686898JB_tlWCNLx\”,\”jqstat\”:\”JOB_UNKNOWN\”,\”jrstat\”:\”
   NONE\”,\”jvstat\”:\”NONE\”,\”jctime\”:1594749529.020721,\”jftime\”:1594755534.931814},\”\\/
   compliance\\/index_files\”:{\”ljid\”:\”j-04mzvk\”,\”rtarget\”:\”paths|\\/compliance\\/
   index_files\”,\”ptype\”:\”is_page\”,\”hashes\”:[\”1b0c4f81aaf64425d051d4db974c1797\”],\”
   hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”file\”:null,\”jid\”:\”53686915ITViZ_Jb0m\”,\”
   jqstat\”:\”JOB_UNKNOWN\”,\”jrstat\”:\”NONE\”,\”jvstat\”:\”NONE\”,\”jctime\”:1594749803.409561,\”
   jftime\”:1594755545.427616},\”\\/hs\\/cta\\/cta\\/redirect\\/442215\\/e1fd8da7-
   8632-43ee-8b19-3cd819d1b290\\/\”:{\”ljid\”:\”j-htzqqx\”,\”rtarget\”:\”paths|\\/
   hs\\/cta\\/cta\\/redirect\\/442215\\/e1fd8da7-8632-43ee-8b19-3cd819d1b290\\/\”,\”
   ptype\”:\”is_page\”,\”hashes\”:[\”8f069fc40d15c90411e55506fe7c7fa9\”],\”hash\”:\”
   8f069fc40d15c90411e55506fe7c7fa9\”,\”file\”:null,\”jid\”:\”53506594ltEHfyJOhA\”,\”
   jqstat\”:\”JOB_UNKNOWN\”,\”jrstat\”:\”NONE\”,\”jvstat\”:\”NONE\”,\”jctime\”:1594483603.261504,\”
   jftime\”:1594594136.987899},\”\\/sales-thank-you\\/2\\/fck\”:{\”ljid\”:\”j-01eazl\”,\”
   rtarget\”:\”paths|\\/sales-thank-you\\/2\\/fck\”,\”ptype\”:\”is_page\”,\”hashes\”:[\”
   1b0c4f81aaf64425d051d4db974c1797\”],\”hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”
   file\”:null,\”jid\”:\”53718332o5DL7P-p6-\”,\”jqstat\”:\”JOB_ONGOING\”,\”jrstat\”:
   null,\”jvstat\”:null,\”jctime\”:1594783790.927484,\”jftime\”:null},\”\\/company\\/
   newsroom\\/employers-say-accommodating-millennials-is-a-business-imperative\\/
   aspnet\”:{\”ljid\”:\”j-01omnp\”,\”rtarget\”:\”paths|\\/company\\/newsroom\\/employers-
   say-accommodating-millennials-is-a-business-imperative\\/aspnet\”,\”ptype\”:\”
   is_page\”,\”hashes\”:[\”1b0c4f81aaf64425d051d4db974c1797\”],\”hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”
   file\”:null,\”jid\”:null,\”jqstat\”:\”NEW\”,\”jrstat\”:null,\”jvstat\”:null,\”
   jctime\”:1594774112.44033,\”jftime\”:null},\”\\/wp-content\\/themes\\/goodhire\\/
   data\\/config.inc\”:{\”ljid\”:\”j-01pwce\”,\”rtarget\”:\”paths|\\/wp-content\\/
   themes\\/goodhire\\/data\\/config.inc\”,\”ptype\”:\”is_page\”,\”hashes\”:[\”1b0c4f81aaf64425d051d4db974c1797\”],\”
   hash\”:\”1b0c4f81aaf64425d051d4db974c1797\”,\”file\”:null,\”jid\”:null,\”jqstat\”:\”
   NEW\”,\”jrstat\”:null,\”jvstat\”:null,\”jctime\”:1594771889.252337,\”jftime\”:
   null},\”\\/contact-us\\/00\\/cleanup.log\”:{\”ljid\”:\”j-01tmjt\”,\”rtarget\”:\”
   paths|\\/contact-us\\/00\\/cleanup.log\”,\”ptype\”:\”is_page\”,\”hashes\”:[\”
   1b0c4f81aaf64425d051d4db974c1797\”],\”hash\”:\”1b0c4f81aaf64425d051d4db974c17
 * My other suspicion is the “Enable 404 fallbacks?” setting, which was recently
   turned off because it was generating errors on some dev environments and we assumed
   was problematic with the way Pantheon handles file permissions.
 * Any thoughts on this would be greatly appreciated.
 * Thank you,
    Ben
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13127958)
 * although I cannot rule out that the problem is due to the 404’s not being recognized,
   there is not really anything that indicates that in fact the problem bcupham.
   for a separate topic I was looking into the max size of option values in wp_options
   and that according to [this knowledgeable stackexchange answer](https://wordpress.stackexchange.com/a/71016/168954)
   that would be .. 4GB, so queue size would have to be humongous really to surpass
   that threshold. but as I wrote; i can’t rule it out so as stated before you really
   should get a hold on that 404’s not being recognized issue, this _could_ be the
   root cause.
 * as for the 404 fallback: don’t see how that would impact database usage, given
   it does not store data (except for a true/false flag)?
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13128267)
 * Hi Frank,
 * Thanks for the info. We have fixed it for now. We were using the beta version
   on prod (which I know was a bad idea, we were hoping to use the fix you kindly
   provided, which ended up not working). We’ve rolled back to AO 2.6.
 * However, now CriticalCSS is not working — no rules are going in the job queue
   and looking at our account on CriticalCSS.com it looks like no API requests have
   been made in over 7 hours, since the incident. Is it possible they blocked our
   API requests during the problem?
 * Thank you,
    Ben
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13129165)
 * why back to 2.6 iso 2.7.3 which is the latest “stable” version?
 * re. critical css; you will likely have to remove the queue-lockfile; `wp-content/
   uploads/ao_ccss/queue.lock` ?
 * frank
 *  Thread Starter [bcupham](https://wordpress.org/support/users/bcupham/)
 * (@bcupham)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/#post-13132288)
 * Thanks, Frank. We rolled back to 2.6 because that was the only version we had
   tested. I will get the queue.lock file removed.
 * Thanks again for all your help. I don’t know exactly what the relationship is
   between you and the CriticalCSS people, but I’ve found their “support” to be 
   very weak. Given that they are the ones we are actually paying money to the contrast
   is pretty striking (although I assume you get a %, or maybe it’s your company?).
   I like the service they provide, but for an agency like us working on behalf 
   of clients, we need a reliable way to reach someone when something goes wrong.
   Even if it’s just to say “talk to AO support”. 🙂
 * Thanks again,
    Ben

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

1 [2](https://wordpress.org/support/topic/help-with-path-based-rules/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/help-with-path-based-rules/page/2/?output_format=md)

The topic ‘Help with path-based rules’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/autoptimize-criticalcss.svg)
 * [Autoptimize criticalcss.com power-up](https://wordpress.org/plugins/autoptimize-criticalcss/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize-criticalcss/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize-criticalcss/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize-criticalcss/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize-criticalcss/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize-criticalcss/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/help-with-path-based-rules/page/2/#post-13132472)
 * Status: resolved