Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter marketsys

    (@marketsys)

    301s from wordpress core canonical redirects are cached as blank pages

    eg

    https://www.sitename.com/category1/a_page_name

    canonical redirect goes to

    https://www.sitename.com/section/category1/a_page_name

    on first access https://www.sitename.com/category1/a_page_name redirects to
    https://www.sitename.com/section/category1/a_page_name and displays page

    on subsequent access https://www.sitename.com/category1/a_page_name returns cache page (blank page)
    on subsequent access https://www.sitename.com/category1/a_page_name returns correctly cached page.

    If turn off canonical redirect in core with remove_filter(‘template_redirect’, ‘redirect_canonical’);

    both urls are cached correctly (however 1 is obviously a duplicate and unncessary)

    Need to get this plugin to ignore the 301 pages in cache but patch linked above isn’t working

    Thread Starter marketsys

    (@marketsys)

    ok, turns out I pasted the patch wrongly inside another if statement so it does work and 301/302 is no longer cached..

    should be in function _can_cache2 :

    function _can_cache2(&$buffer) {
    /**
    * Skip if caching is disabled
    */
    if (!$this->_caching) {
    return false;
    }

    /**
    * Check for database error
    */
    if (w3_is_database_error($buffer)) {
    $this->cache_reject_reason = ‘Database error occurred’;

    return false;
    }

    /**
    * Check for DONOTCACHEPAGE constant
    */
    if (defined(‘DONOTCACHEPAGE’) && DONOTCACHEPAGE) {
    $this->cache_reject_reason = ‘DONOTCACHEPAGE constant is defined’;

    return false;
    }

    /**
    * Check hostname
    */
    if ((!w3_is_multisite() || (w3_is_multisite() && !w3_force_master())) &&
    $this->_config->get_boolean(‘pgcache.check.domain’) && w3_get_host() != w3_get_home_domain()) {
    $this->cache_reject_reason = ‘Hostname mismatch’;

    return false;
    }

    /**
    * Don’t cache 404 pages
    */
    if (!$this->_config->get_boolean(‘pgcache.cache.404’) && function_exists(‘is_404’) && is_404()) {
    $this->cache_reject_reason = ‘Page is 404’;

    return false;
    }

    /**
    * Don’t cache homepage
    */
    if (!$this->_config->get_boolean(‘pgcache.cache.home’) && function_exists(‘is_home’) && is_home()) {
    $this->cache_reject_reason = is_front_page() && is_home() ? ‘Page is front page’ : ‘Page is posts page’;

    return false;
    }

    /**
    * Don’t cache front page
    */
    if ($this->_config->get_boolean(‘pgcache.reject.front_page’) && function_exists(‘is_front_page’) && is_front_page() && !is_home()) {
    $this->cache_reject_reason = ‘Page is front page’;

    return false;
    }

    /**
    * Don’t cache feed
    */
    if (!$this->_config->get_boolean(‘pgcache.cache.feed’) && function_exists(‘is_feed’) && is_feed()) {
    $this->cache_reject_reason = ‘Page is feed’;

    return false;
    }

    /**
    * Check if page contains dynamic tags
    */
    if ($this->_enhanced_mode && $this->_has_dynamic($buffer)) {
    $this->cache_reject_reason = ‘Page contains dynamic tags (mfunc or mclude) can not be cached in enhanced mode’;
    return false;
    }

    /**
    * Don’t cache redirects (301,302)
    */
    if (in_array(http_response_code(),array(301,302)) ){
    return false;
    }

    return true;
    }

    Thread Starter marketsys

    (@marketsys)

    better off using the full if statement like:

    if (function_exists(‘http_response_code’) && in_array(http_response_code(),array(301,302)) ){
    return false;
    }

    as http_response_code function only exists in php > 5.4

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘crock of shit plugin is still caching 301 redirects as blank pages’ is closed to new replies.