Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function onAfterRender()
- {
- $url = (isset($_SERVER['HTTPS']) ? "https" : "http").'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
- // Don't cache the admin area, maybe this can be improved also.
- if (strpos($url, 'administrator') !== false) {
- return;
- }
- $urlParts = parse_url($url);
- $uri = $urlParts['path'] !== '/' ? $urlParts['path'] : '/index';
- $uri = str_replace(['.html', '.php'], '', $uri).'.html';
- $file = JPATH_BASE . "/cache/static$uri";
- if (!is_dir(dirname($file))) {
- mkdir(dirname($file), 0777, true);
- }
- file_put_contents($file, $this->app->getBody());
- }
- RewriteEngine On
- # Rewrite to html cache if it exists and the request is off a static page (no url query params and only get requests)
- RewriteCond %{REQUEST_METHOD} GET
- RewriteCond %{QUERY_STRING} !.*=.*
- RewriteCond %{DOCUMENT_ROOT}/cache/static%{REQUEST_URI}.html -f
- RewriteRule ^(.*)$ /cache/static%{REQUEST_URI}.html [L]
- # This is specific to cache the index when it' accesed vie /
- RewriteCond %{REQUEST_METHOD} GET
- RewriteCond %{QUERY_STRING} !.*=.*
- RewriteCond %{DOCUMENT_ROOT}/cache/static/index.html -f
- RewriteCond %{REQUEST_URI} ^/$
- RewriteRule .* /cache/static/index.html [L]
Add Comment
Please, Sign In to add comment