Skip to content

Instantly share code, notes, and snippets.

@chrisdempsey
Forked from opengeek/.htaccess
Last active August 29, 2015 14:06
Show Gist options
  • Save chrisdempsey/f4f1234773bc8158feb8 to your computer and use it in GitHub Desktop.
Save chrisdempsey/f4f1234773bc8158feb8 to your computer and use it in GitHub Desktop.
# 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]
<?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;
}
<!-- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment