I try to use Staticache, and the files are generated.
I try to redirect to the static files if they exist. But I don’t get it work for now.
This is my index.php in the root of the installation:
<?php
(function /* staticache */ () {
$root = __DIR__ . '/site/cache';
// check if a cache for this domain exists
$root .= '/' . $_SERVER['SERVER_NAME'] . '/pages';
if (is_dir($root) !== true) {
return;
}
// determine the exact file to use
$path = $root . '/' . ltrim($_SERVER['REQUEST_URI'] ?? '', '/');
if (is_file($path . '/index.html') === true) {
// a HTML representation exists in the cache
$path = $path . '/index.html';
} elseif (is_file($path) !== true) {
// neither a HTML representation nor a custom
// representation exists in the cache
return;
}
// try to determine the content type from the static file
if ($mime = @mime_content_type($path)) {
header("Content-Type: $mime");
}
die(file_get_contents($path));
})();
require __DIR__ . '/kirby/bootstrap.php';
echo (new Kirby)->render();
But somehow the site does not redirect to the page, because I don’t see the timestamp on the bottom of the pages after the html tag.
I also changed the htacces file to this:
# Kirby .htaccess
# revision 2023-07-22
# rewrite rules
<IfModule mod_rewrite.c>
# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on
# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder;
# otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite,
# set the RewriteBase to:
#
# RewriteBase /mysite
# In some environments it's necessary to
# set the RewriteBase to:
#
# RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/site/cache/%{SERVER_NAME}/pages/%{REQUEST_URI}/index.html -f [NC]
RewriteRule ^(.*) %{DOCUMENT_ROOT}/site/cache/%{SERVER_NAME}/pages/%{REQUEST_URI}/index.html [END]
RewriteCond %{DOCUMENT_ROOT}/site/cache/%{SERVER_NAME}/pages/%{REQUEST_URI} -f [NC]
RewriteRule ^(.*) %{DOCUMENT_ROOT}/site/cache/%{SERVER_NAME}/pages/%{REQUEST_URI} [END]
# block files and folders beginning with a dot, such as .git
# except for the .well-known folder, which is used for Let's Encrypt and security.txt
RewriteRule (^|/)\.(?!well-known\/) index.php [L]
# block all files in the content folder from being accessed directly
RewriteRule ^content/(.*) index.php [L]
# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) index.php [L]
# block direct access to Kirby and the Panel sources
RewriteRule ^kirby/(.*) index.php [L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
</IfModule>
# pass the Authorization header to PHP
SetEnvIf Authorization "(.+)" HTTP_AUTHORIZATION=$1
# compress text file responses
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
# set security headers in all responses
<IfModule mod_headers.c>
# serve files as plain text if the actual content type is not known
# (hardens against attacks from malicious file uploads)
Header set Content-Type "text/plain" "expr=-z %{CONTENT_TYPE}"
Header set X-Content-Type-Options "nosniff"
</IfModule>
But no luck. What am I doing wrong? I use the starterkit now for testing purposes.
Thanks!