Some Tome users may find it useful to use Tome Static only as a caching layer for their Drupal site, serving some requests from the static export directory and others from Drupal. This is similar to how the Boost module worked, the main difference being that Tome generates all static pages before hand and Boost did so on-demand.
PHP
Here's a snippet you could add to settings.php to conditionally serve pages from your static export directory.
Note that this code is just an example and needs to be reviewed and tested before production use:
// Add this code to the bottom of settings.php
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// Check if the incoming path is for a user-facing path.
if (strpos($path, '/admin') !== 0 && !preg_match('|^/node/.*/edit$|', $path)) {
$path = realpath('../html' . $path);
if (is_dir($path)) {
$path .= '/index.html';
}
// HTML pages are updated often and should have an expiry.
if (pathinfo($path, PATHINFO_EXTENSION) === 'html') {
header('Cache-Control: public, max-age=600');
}
// If the file exists and is safe to serve, do so.
if (strpos($path, realpath('../html')) === 0 && file_exists($path)) {
echo file_get_contents($path);
die;
}
// Fallback to a simple 404.
header('HTTP/1.0 404 Not Found');
echo 'File not found.';
die;
}
Apache
Here's a snippet that should work with .htaccess files. The "html" folder needs to be in the same directory level as your Apache document root as rewrites to parent directories (i.e. ../html) are not allowed.
Note that this code is just an example and needs to be reviewed and tested before production use:
RewriteEngine On
RewriteRule !^(admin.*|node/.*/edit) /html/$1
If you find bugs in these examples, or want to add more, please file an issue at drupal-tome/drupal-tome.github.io and let me know!