WooCommerce Categories Pages Not Working – Permanent Fix Needed

#938683
  • Resolved Standard Cold Pressed Oil
    Rank Math free

    I have been facing an issue over the last two days where specific WooCommerce category pages intermittently show a “404 Page Not Found” error, particularly during the evening.

    Affected pages include:

    https://standardcoldpressedoil.com/spices
    https://standardcoldpressedoil.com/himalayan-salt
    https://standardcoldpressedoil.com/honey

    Current Configuration

    I am using the “Strip Base” feature in the Rank Math SEO plugin, which removes the /product-category and /products prefixes from WooCommerce category and product URLs.

    Observed Behavior

    The “404 Page Not Found” issue occurs intermittently, causing the above category pages to break.
    To temporarily resolve this, I have to deactivate and then reactivate the Rank Math plugin each time the issue arises. So that these categories pages started working.

    Questions and Concerns:

    1. Why does this issue keep happening?
    2. Is this related to WooCommerce, Rank Math, or server settings?
    3. How can this issue be permanently resolved so that I don’t need to deactivate/reactivate the plugin repeatedly?

    Expected Resolution

    I need a permanent fix for this issue so that the affected category pages work consistently, without requiring manual intervention. Kindly investigate the root cause and provide a solution as soon as possible.

    Looking forward to your assistance.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Hello,

    Thank you for contacting us and sorry for any inconvenience that might have been caused due to that.

    From the description you’ve shared, it looks like the permalinks are not sticking for more than a couple of hours and that’s why you’re facing this issue frequently. We’ve seen some similar issues in the past and the most common fix for this kind of issue is to refresh the permalinks programmatically.

    To do that, you could add the following snippet to flush the permalinks every hour and prevent the error from appearing:

    add_action('my_hourly_event', 'do_this_hourly');
     
    function my_activation() {
        if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
            wp_schedule_event(time(), 'hourly', 'my_hourly_event');
        }
    }
     
    add_action('wp', 'my_activation');
     
    function do_this_hourly() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
    

    Here’s how you can add filter/hook to your WordPress site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Hi Team

    Still, the issue is not resolved, I have added the given script in child theme functions.php

    /* Rank Math Issue Permalink Resolve */

    add_action(‘my_hourly_event’, ‘do_this_hourly’);

    function my_activation() {
    if ( !wp_next_scheduled( ‘my_hourly_event’ ) ) {
    wp_schedule_event(time(), ‘hourly’, ‘my_hourly_event’);
    }
    }

    add_action(‘wp’, ‘my_activation’);

    function do_this_hourly() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }

    /* Rank Math Issue Permalink Resolve Ends here */

    Can you please provide a PERMANENT SOLUTION FOR THIS ISSUE?

    The SEO team says that our website traffic drops in google because of this. This is a serious issue, please address it ASAP.

    Hello,

    Could you please add the following filter to your website?

    
    add_filter( 'rank_math/woocommerce/product_redirection', '__return_false' );
    

    If you are not sure how to add filters please follow the steps here: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes. Looking forward to helping you.

    Hi Team

    I have added filter.

    But Still, we are facing the same issue.

    The “404 Page Not Found” issue occurs intermittently, causing the category pages of https://standardcoldpressedoil.com/ to break.
    To temporarily resolve this, I have to deactivate and then reactivate the Rank Math plugin each time the issue arises. So that these categories pages started working.

    Please resolve it ASAP and provide a permanent solution. Otherwise, I have to go with the “Yoast SEO” standard plugin.

    Hello,

    Please ensure all plugins and theme are updated to their latest versions to avoid compatibility issues.

    It is possible another process or plugin is flushing the rewrite rules improperly.

    You can also try adding the following snippet to your child theme’s functions.php to ensure that WooCommerce category pages retain their structure:

    
    function flush_rewrite_once() {
        if ( get_option('rewrite_rules_flushed') !== true ) {
            flush_rewrite_rules(true);
            update_option('rewrite_rules_flushed', true);
        }
    }
    add_action('init', 'flush_rewrite_once');
    

    If the issue persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hi Team,

    I have added this new script to the theme’s child functions.php. The overall code looks like:

    /* Rank Math Issue Permalink Resolve */

    add_action(‘my_hourly_event’, ‘do_this_hourly’);

    function my_activation() {
    if ( !wp_next_scheduled( ‘my_hourly_event’ ) ) {
    wp_schedule_event(time(), ‘hourly’, ‘my_hourly_event’);
    }
    }

    add_action(‘wp’, ‘my_activation’);

    function do_this_hourly() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }

    add_filter( ‘rank_math/woocommerce/product_redirection’, ‘__return_false’ );

    /* Rank Math Issue Permalink Resolve Ends here */

    /* To WooCommerce category pages retain their structure Starts Here */

    function flush_rewrite_once() {
    if ( get_option(‘rewrite_rules_flushed’) !== true ) {
    flush_rewrite_rules(true);
    update_option(‘rewrite_rules_flushed’, true);
    }
    }
    add_action(‘init’, ‘flush_rewrite_once’);

    /* To WooCommerce category pages retain their structure Ends Here */

    Is this correct?

    Hello,

    The two snippets serve 2 different close functions. The first flushes the WordPress rewrite rules every hour. It ensures that the URL structures (permalinks) are refreshed to prevent intermittent 404 errors.

    The other flushes rewrite rules if a custom option (rewrite_rules_flushed) is not set to true in the WordPress database. Once the rules are flushed, it sets the option rewrite_rules_flushed to true to prevent repeated flushing on subsequent page loads.

    Adding both shouldn’t cause any issues.

    Please check and confirm that the issue no longer occurs.

    We look forward to hearing back from you.

    Thanks.

    Ok

    Hello,

    We are glad to be of help

    Do you still need our assistance with anything else or can we go ahead to close the ticket?

    We look forward to helping you.

    Thank you.

    I have observed the following URLs for product pages:

    https://standardcoldpressedoil.com/buy/poongar-red-rice
    https://standardcoldpressedoil.com/poongar-red-rice

    https://standardcoldpressedoil.com/buy/arubatham-kuruvai
    https://standardcoldpressedoil.com/arubatham-kuruvai

    I enabled the “Strip base” setting for product pages and changed the product base prefix from “products” to “buy.”

    Previously, all product URLs with the “buy” prefix (e.g., https://standardcoldpressedoil.com/buy/poongar-red-rice and https://standardcoldpressedoil.com/buy/arubatham-kuruvai) would correctly redirect to the base URL without the prefix (e.g., https://standardcoldpressedoil.com/poongar-red-rice and https://standardcoldpressedoil.com/arubatham-kuruvai).

    However, this redirection is no longer functioning as expected. Could you clarify why this behavior has changed and how to resolve it?

    Hello,

    Apologies for the delay as this ticket seems to have been stuck in our drafts section for some reason.

    The redirection is not working due to the filter we have previously shared above.

    If you add it, then the redirection for remove base feature will be disabled:
    https://rankmath.com/kb/disable-custom-product-redirection/#disable-redirection

    You can remove that filter and clear your website’s cache.

    Looking forward to helping you.

    I am not clear. Can you explain what to do?

    Yes i have added all the script which you have given in child theme file.

    What is the next step? Please advise.

    Hello,

    To clarify, the issue with redirection and the “Strip Base” feature arises due to the filter we previously provided:

    add_filter( 'rank_math/woocommerce/product_redirection', '__return_false' );

    If you have added this filter, it disables the automatic redirection functionality for the “Remove Base” feature for the product URLs.

    Next Steps:
    1. Remove the Filter: Remove the following filter from your child theme’s functions.php file:

    add_filter( 'rank_math/woocommerce/product_redirection', '__return_false' );

    2. Clear Cache: After removing the filter, clear your website’s cache (including server-side, plugin, and browser cache).

    3. Test the URLs: Check if the redirection from /buy/ to the base URL without the prefix works as expected.

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Thanks, it is working now.

    Hopefully, the 404 page error will not arise in the future. Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘WooCommerce Categories Pages Not Working – Permanent Fix Needed’ is closed to new replies.