Title: Enable 404 fallbacks option &#8211; code issue
Last modified: September 18, 2020

---

# Enable 404 fallbacks option – code issue

 *  Resolved [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/)
 * On 3 separate sites on 3 different host servers the Enable 404 fallbacks option
   code below is not creating the ErrorDocument 404 line of htaccess code in the
   Autoptimize cache folder htaccess file.
 *     ```
                   if ( self::do_fallback() === true ) {
                       $content .= "\nErrorDocument 404 " . trailingslashit( parse_url( content_url(), PHP_URL_PATH ) ) . 'autoptimize_404_handler.php';
                   }
                   @file_put_contents( $htaccess, $content ); // @codingStandardsIgnoreLine
       ```
   

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

1 [2](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/page/2/?output_format=md)

 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13426136)
 * Wow ok this is weird. I deactivated and reactivated AO and the problem was still
   occurring. I’m pretty sure that I resaved option settings, but maybe I didn’t
   previously. I deactivated and reactivated AO again and resaved the option settings
   and this time the ErrorDocument line of htaccess code was successfully created.
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13426178)
 * Ok I see the issue that happened now. Uninstalled AO, reinstalled AO, the ErrorDocument
   line of htaccess code is not created in the AO cache htaccess file even though
   the Enable 404 fallbacks option is checked by default. Clicked the AO Save Changes
   button with the Enable 404 fallbacks option checkbox checked does not create 
   the ErrorDocument line of htaccess code. Deactivating and reactivating AO DOES
   automatically create the ErrorDocument line of htaccess code. So it looks like
   even though the Enable 404 fallbacks option checkbox is checked, things are not
   happening as they should be. 😉
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13426222)
 * On one of the sites when the AO Enable 404 fallbacks option is used WooCommerce
   Store/Shop links are broken with 404 errors IF the BPS Root BulletProof Mode 
   htaccess file is in play/activated. That was what I was originally troubleshooting.
   Anyway that is a problem for another day since unchecking the Enable 404 fallbacks
   option no longer breaks the WooCommerce Store/Shop links. When I have time to
   dig deeper into why that is occurring on that 1 particular site, I’ll let you
   know why that is.
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13426704)
 * when you enable the option, try removing the existing .htaccess file to allow
   AO to re-write it?
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13426769)
 * The only existing AO htaccess file in the /wp-content/cache/autoptimize/ folder
   was the htaccess file that AO created. I did experiment with that though already.
   The results are exactly the same with the difference being that AO creates a 
   new AO htaccess file with the ErrorDocument line of htaccess code in it. ie on
   first time AO plugin installation and activation the AO htaccess file is created,
   deleted the AO htaccess file, clicked the AO Save Changes button with the Enable
   404 fallbacks option checkbox checked does not create the ErrorDocument line 
   of htaccess code, deactivate and reactivate the AO plugin
    again does create 
   the ErrorDocument line of htaccess code.
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13426858)
 * and when you click “save changes and empty cache”?
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427362)
 * Before doing any additional testing I have a question. The question is this: 
   Is the Enable 404 fallbacks option supposed to be pre-saved by default or is 
   the Enable 404 fallbacks option checkbox checked as a “recommended” option setting?
   The way my plugin’s checkbox forms work is that a checkbox is only checked if
   the option’s form value = isset. Or in other words, that particular plugin option
   is already saved to the DB if the checkbox is checked when the form is not being
   submitted.
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427380)
 * Your are using this form “checked” processing code:
    `echo autoptimizeOptionWrapper::
   get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?
   >`
 * I typically use the WordPress checked() function:
    `checked( $PFW_whitelist_options['
   bps_pfw_google'], 1 );`
 * What I will look at next is to see if the db option value for the Enable 404 
   fallbacks option is saved to the DB on AO installation and activation. Then check
   through the various stages for when the Enable 404 fallbacks option is saved 
   to the DB.
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427388)
 * I checked through all of your code and I don’t see an instance of the update_option()
   function used for the Enable 404 fallbacks option. So maybe you do not want the
   Enable 404 fallbacks option to be pre-saved to the DB?
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427409)
 * it’s set in the dafaults on code level, see [https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeConfig.php#L755](https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeConfig.php#L755)
 * that being said, I seem to have forgotten to also assume it’s on if the setting
   is fetched but not found in a [autoptimizeCache.php on line 650](https://github.com/futtta/autoptimize/blob/beta/classes/autoptimizeCache.php#L650),
   will update that on beta.
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427410)
 * and pushed to beta 🙂
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427435)
 * AO Testing for the Enable 404 fallbacks option:
    ###################################
 * Plugin installation and activation:
    ################################### The 
   Enable 404 fallbacks option form checkbox is checked. The AO htaccess file is
   created without the ErrorDocument line of htaccess code. The autoptimize_cache_fallback
   DB option does NOT exist (is not pre-saved to the WP DB).
 * Clicking the “Save Changes” button on the Autoptimize Settings page:
    ###################################
   The Enable 404 fallbacks option form checkbox is checked. The AO htaccess is 
   not updated/written to. The ErrorDocument line of htaccess code is not written
   to the AO htaccess file. The autoptimize_cache_fallback DB option does exist/
   has been created/saved with a value of: on Note: The DB option value is NOT serialized.
 * AO htaccess file deletion and resaving of AO plugin settings:
    ###################################
   The Enable 404 fallbacks option form checkbox is checked. The AO htaccess is 
   updated/written to. The ErrorDocument line of htaccess code is written to the
   AO htaccess file.
 * AO plugin deactivation and reactivation:
    ###################################
   The Enable 404 fallbacks option form checkbox is checked. The AO htaccess is 
   updated/written to. The ErrorDocument line of htaccess code is written to the
   AO htaccess file.
 * Summary|Conclusion:
    ################################### Either the Enable 404
   fallbacks option is not intended to be pre-saved and the checkbox is checked 
   as a “recommendation” or there is a logic flaw in the AO code.
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
    -  This reply was modified 5 years, 8 months ago by [AITpro](https://wordpress.org/support/users/aitpro/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427448)
 * guess your reply is held in moderation, but I did receive it by notification 
   mail already aitpro 🙂
 * feedback:
    -> do also test with “save changes & empty cache” -> do test with 
   the beta-version which has the previously mentioned bugfix
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427451)
 * The post/thread is currently being held in moderation after 2 edits and I need
   to do 1 more edit for 1 more typo. Pending update once a WP moderator has had
   a chance to review the post/thread. The edit/typo is this: The AO htaccess “file”
   is…
 *  Thread Starter [AITpro](https://wordpress.org/support/users/aitpro/)
 * (@aitpro)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/#post-13427456)
 * Well I think the test results show that there is an issue unless I am misunderstanding
   the intention of the Enable 404 fallbacks form checkbox. The issue would either
   be that it is unclear that the Enable 404 fallbacks is already enabled on plugin
   installation and activation or the checkbox is checked as a “recommendation” 
   and is not enabled until someone saves AO settings, but that still leaves this
   issue > The ErrorDocument line of htaccess code in the AO htaccess file is NOT
   created when clicking the Save Changes button on the AO Settings page. To me 
   it seems like this is a bug that needs to be taken care of. 😉

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

1 [2](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/page/2/?output_format=md)

The topic ‘Enable 404 fallbacks option – code issue’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

 * 22 replies
 * 2 participants
 * Last reply from: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/enable-404-fallbacks-option-code-issue/page/2/#post-13427637)
 * Status: resolved