chrisdempsey
9/15/2014 - 4:30 PM

.htaccess

<!-- web.config versin of Jason Coward's (Opengeek) .htaccess file -->

<rewrite>
  <rules>
    <rule name="Rewrite Statcache" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="/abs/path/to/docroot/statcache{URL}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="Rewrite" url="/statcache/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>
<?php
switch ($modx->event->name) {
    case 'OnBeforeSaveWebPageCache':
        if ($modx->resource->_output != '') {
            $statcacheFile = $modx->getOption('statcache_path', $scriptProperties, MODX_BASE_PATH . 'statcache/') . $modx->makeUrl($modx->resource->get('id'));
            if (!$modx->cacheManager->writeFile($statcacheFile, $modx->resource->_output)) {
                $modx->log(modX::LOG_LEVEL_ERROR, "Error caching output from Resource {$modx->resource->get('id')} to static file {$statcacheFile}", '', __FUNCTION__, __FILE__, __LINE__);
            }
        }
        break;
}
# Add this before your MODX Friendly URLs RewriteCond's and RewriteRule...
RewriteCond /abs/path/to/docroot/statcache%{REQUEST_URI} -f
RewriteRule ^(.*)$ /statcache/$1 [L,QSA]