Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public function onAfterRender()
  2. {
  3. $url = (isset($_SERVER['HTTPS']) ? "https" : "http").'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  4.  
  5. // Don't cache the admin area, maybe this can be improved also.
  6. if (strpos($url, 'administrator') !== false) {
  7. return;
  8. }
  9.  
  10. $urlParts = parse_url($url);
  11. $uri = $urlParts['path'] !== '/' ? $urlParts['path'] : '/index';
  12. $uri = str_replace(['.html', '.php'], '', $uri).'.html';
  13. $file = JPATH_BASE . "/cache/static$uri";
  14.  
  15. if (!is_dir(dirname($file))) {
  16. mkdir(dirname($file), 0777, true);
  17. }
  18. file_put_contents($file, $this->app->getBody());
  19. }
  20.  
  21. RewriteEngine On
  22.  
  23. # Rewrite to html cache if it exists and the request is off a static page (no url query params and only get requests)
  24. RewriteCond %{REQUEST_METHOD} GET
  25. RewriteCond %{QUERY_STRING} !.*=.*
  26. RewriteCond %{DOCUMENT_ROOT}/cache/static%{REQUEST_URI}.html -f
  27. RewriteRule ^(.*)$ /cache/static%{REQUEST_URI}.html [L]
  28.  
  29. # This is specific to cache the index when it' accesed vie /
  30. RewriteCond %{REQUEST_METHOD} GET
  31. RewriteCond %{QUERY_STRING} !.*=.*
  32. RewriteCond %{DOCUMENT_ROOT}/cache/static/index.html -f
  33. RewriteCond %{REQUEST_URI} ^/$
  34. RewriteRule .* /cache/static/index.html [L]
Add Comment
Please, Sign In to add comment