Solving the Facebook Post Sharing Issue with Comet Cache and Super Page Cache

If you're using caching plugins like Comet Cache or Super Page Cache alongside CleanTalk Security FireWall or CleanTalk Anti-Spam's Anti-Crawler, Anti-Flood, and SpamFireWall features, you might have encountered a problem: your caching plugins could be saving blocking pages intended for bots. This can result in real users accidentally seeing these cached blocking pages when trying to share posts on Facebook.

What's the core of the problem?

When CleanTalk identifies a bot, it generates a blocking page with an HTTP 403 Forbidden response. This status code indicates that the server received the request but refuses to fulfill it because access to the requested resource is forbidden. CleanTalk blocking pages also include special tags that explicitly prohibit their caching. This is designed to ensure that regular website visitors never see these pages.

However, despite these precautions, Comet Cache and Super Page Cache have a peculiarity: they can cache even pages with a 403 response. As a result, if a bot visited a page and was blocked, that blocking page might get cached. The next time a real visitor tries to access the same page, they might be shown that exact cached blocking page instead of the expected content.

 

To fix this, you need to exclude the URLs Facebook uses to collect metadata from Comet Cache's caching. Typically, Facebook sends requests with specific User-Agents.

Add an exclusion for the Facebook Bot User-Agent in Comet Cache:

  1. Navigate to the Comet Cache plugin settings in your WordPress admin dashboard: Plugins →  Comet Cache

  2. Find the User-Agent Exclusion section.

  3. Add the following User-Agents that Facebook uses to the User-Agent exclusion list: facebot, facebookexternalhit.

  4. Save your changes.

  5. After adding the exclusion, ensure that you completely clear all cached data within Comet Cache.

URL Exclusions in Comet Cache

 

  1. Add the following code in the function.php file of your active theme:

    For Anti-Spam:
    add_action('apbct_firewall_before_die', function ($_result) {
        if ( ! headers_sent() ) {
            $cookie_name       = 'apbct_firewall_die';
            $cookie_value      = '1';
            $cookie_expiration = time() + 3600; // 1 hour
            $cookie_path       = '/';
            setcookie($cookie_name, $cookie_value, $cookie_expiration, $cookie_path);
        }
    });​

    For Security

    add_action('spbct_firewall_before_die', function ($_result) {
        if ( ! headers_sent() ) {
            $cookie_name       = 'spbc_firewall_die';
            $cookie_value      = '1';
            $cookie_expiration = time() + 3600; // 1 hour
            $cookie_path       = '/';
            setcookie($cookie_name, $cookie_value, $cookie_expiration, $cookie_path);
        }
    });​
  2. Navigate to the Super Page Cache settings in your WordPress admin dashboard: Plugins → Super Page Cache

  3. Add the following cookies to the Super Page Cache exclusion list:
    For Anti-Spam: apbct_firewall_die 
    For Security: spbc_firewall_die

  4. Update settings.

  5. After adding the exclusion, ensure that you completely clear all cached data within Super Page Cache.

Cookies Exclusions in Super Page Cache

 

This might be helpful

 

Need help?

Thanks for being with us!

Was this information helpful?

Copied to clipboard