• The problem is similar to this topic
    I can’t figure out what the reason is.
    More precisely, I cannot repeat the mistake. May appear several times a day,
    or maybe everything is fine for a week, and then all categories have a 404 error.

    I don’t use caching plugins.

    Everything is fine on other sites. Possibly interacts with server caching modules? gtranslate also caches and interacts with links, but disabling this plugin did nothing.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter polarone

    (@polarone)

    I left memcache. Memcached and opcache were also enabled (now disabled). Maybe there is a problem with php and opcache?

    Hi @polarone,

    Greetings! Thanks for reaching out.

    I understand that you are having an intermittent issue that ends up with a 404 error. Let me help you with this.

    You mentioned that you have a caching which is now disabled, have you tried clearing your server cache as well then re-save the settings?

    Once this is done, please check if the issue persists.

    If that does not help, please write to us at https://premmerce.com/contact-us/, so we can discuss this further. Thanks in advance!

    Thread Starter polarone

    (@polarone)

    Hello @robfrtlz .
    Thank you.
    Yes, the problem was related to opcache.
    Via php

    opcache_reset();

    I reset the cache and so far the error has not been observed.

    Awesome to hear that you were able to sort it out @polarone.

    Thread Starter polarone

    (@polarone)

    Still didn’t help. Rarely, but this error is repeated.

    Hello,
    I have exactly the same problem. Everything works fine and it can happen once a week or every two weeks, there is no regularity to it. All categories also give a 404 error. Clearing the cache both on the site and on the server does not help. The only way to deal with this is to go into the link structure and save, and then everything gets sorted out.

    Hi @polarone and @ilya115,

    Would you please be kind to submit a ticket on our support platform here: https://premmerce.com/contact-us/

    Thank you so much.

    Thread Starter polarone

    (@polarone)

    I made a hack.
    Checks certain categories and in case of 404 error sends a message to the mail and re-saves the settings.

    Initially I did it in the root directory and protected the file via .htaccess, but for some reason when running on cron the settings were not saved, although the script worked. Apparently something with the rights (didn’t figure it out).

    I did it via a snippet. In this code, logging and sending a message after saving the settings are cut out. It works with a test 404 error, but I haven’t had a chance to check it with a real one yet.

    // Adding a new interval for the cron (60 seconds)
    add_filter('cron_schedules', function ($schedules) {
    $schedules['60sec'] = array(
    'interval' => 60,
    'display' => __('Every 60 seconds'),
    );
    return $schedules;
    });

    // Schedule a cron event on initialization
    add_action('init', function() {
    if (!wp_next_scheduled('check_urls_cron_event')) {
    wp_schedule_event(time(), '60sec', 'check_urls_cron_event');
    }
    });

    // Cron event handler
    add_action('check_urls_cron_event', function() {
    // Список URL-адресов для проверки
    $urls = [
    'https://site.com/category/',
    'https://site.com/category_1/',
    'https://site.com/category_2/'
    ];

    // Email, to which the notification will be sent
    $to = '[email protected]';

    // Letter subject
    $subject = 'Subject 404';

    // Function to check page status
    function checkUrl($url) {
    $headers = @get_headers($url);
    if ($headers && strpos($headers[0], '404') !== false) {
    return '404 Not Found';
    }
    return 'OK';
    }

    // We check all URLs and collect statuses
    $statusMessages = [];
    $has404Error = false;

    foreach ($urls as $url) {
    $status = checkUrl($url);
    $statusMessages[] = "$url: $status";
    if ($status === '404 Not Found') {
    $has404Error = true;
    }
    }

    // Execute script if 404 errors are found
    if ($has404Error) {
    // Executing the script
    require_once(ABSPATH . 'wp-load.php');

    // Checking if WordPress is loaded
    if (function_exists('get_option')) {
    // Get current permanent link settings
    $current_permalink_structure = get_option('permalink_structure');

    // New permanent link structure
    $new_permalink_structure = '/%postname%/';

    // Updating the structure of permanent links
    $result = update_option('permalink_structure', $new_permalink_structure);

    // Rewriting rewriting rules (rewrite rules)
    global $wp_rewrite;
    if (is_object($wp_rewrite) && method_exists($wp_rewrite, 'flush_rules')) {
    $wp_rewrite->flush_rules();
    }

    // Send email after saving settings
    $message = "The status of the checked URLs is as follows:\n\n" . implode("\n", $statusMessages);
    mail($to, $subject, $message);
    }
    }
    });
    Thread Starter polarone

    (@polarone)

    The code has undergone its baptism of fire, it works.
    But that’s just it hack \ workaround

    I have the same issue. Happens completely at random. Not good and really need a resolution as we don’t know until customers complain.

    @greencode,

    Thank you for joining the thread.

    Would you please be kind to submit a ticket on our support platform here: https://premmerce.com/contact-us/

    Thank you so much.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Categories in Woo periodically show a 404 error.’ is closed to new replies.