Hi,
I would like 403 404 and 410 to be cached.
Why?
We use smart error pages in an ecommerce site, for example when a product is definitive out of stock or when catalog URL's change. They contain product data, and it's important to get them cached.
410 isn't handled at all by boost at the moment.

My fix is not complex, and works very good for me. I post code here and will provide patch later if this idea makes sense to the module maintainer(s).

Changes boost.module, function _boost_ob_handler(), line 1397:

      elseif ($status == 404 || $status == 403 || $status == 410) {
        //print $decompressed_buffer;
        //exit;
        switch($status){
          case 403:
            $decompressed_buffer = '<?php header("HTTP/1.0 403 Forbidden"); ?>'.$decompressed_buffer.'<!-- '.$status.' Boost cached -->';
          break;
          case 404:
            $decompressed_buffer = '<?php header("HTTP/1.0 404 Not Found"); ?>'.$decompressed_buffer.'<!-- '.$status.' Boost cached -->';
          break;
          case 410:
            $decompressed_buffer = '<?php header("HTTP/1.0 410 Gone"); ?>'.$decompressed_buffer.'<!-- '.$status.' Boost cached -->';
          break;
        }
        boost_cache_set($GLOBALS['_boost_path'], $decompressed_buffer, '.php');
        // Kill .html cache entry if it exists
        $filename = boost_file_path($GLOBALS['_boost_path'], TRUE, BOOST_FILE_EXTENSION);
      }

Added to .htaccess, before 'BOOST END':

  # 403/404/410
  RewriteCond %{DOCUMENT_ROOT}/cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.php -s
  RewriteRule .* cache/normal/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}\.php [L,T=text/html]

The bottomline of this solution is to cache these as PHP pages, with a header(); added to serve correct http headers.

Regards,

Kees

Comments

keesje’s picture

Also change RewriteRule .* - [S=1] to RewriteRule .* - [S=2] in .htaccess

Regards,

Kees
Kopu webshops

keesje’s picture

Issue summary: View changes

changed