Error 404 when using “Remove category base” for WooCommerce

#595511
  • Resolved Matteo Pizzanelli
    Rank Math free

    Hi,
    I’ve a website with WooCommerce and I’ve enabled “Remove category base” in the WooCommerce tab of rankmath. I must say it’s working because now my product categories url are “www.mywebsite.com/categoryname/” instead of “www.mywebsite.com/product-category/categoryname/”.

    But I’ve noticed that sometimes I got a 404 error for http://www.mywebsite.com/categoryname/ and I need to manually regenerate permalinks to make http://www.mywebsite.com/categoryname/ works again. I don’t know why this happens, it simply happens without any clue ๐Ÿ™

    Do you have any idea why this 404 error happens? How can I fix it?
    Thanks in advance ๐Ÿ™‚

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

    Thank you for contacting Rank Math and bringing your concern to our attention. Iโ€™m sorry for any inconvenience this issue may have caused you.

    We’ve seen this issue in the past where the permalinks are not sticking for more than a couple of hours.

    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();
    }

    And hereโ€™s how you can add the filter to your site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Thank you.

    Hi, thank you very much for your quick reply.
    Ok, I’m gonna try this workaround.
    Thanks again and best regards ๐Ÿ™‚

    Hello,

    Glad that helped.

    If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.

    Looking forward to helping you.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Error 404 when using “Remove category base” for WooCommerce’ is closed to new replies.