Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a simple algo for HTML caching, predicated on the following conditions</p> <ul> <li>The user is a guest (logged on users have a blog_user cookie set)</li> <li>The request URI is a GET that contains no request parameters</li> <li>An HTML cache version of the file exists</li> </ul> <p>then an <code>.htaccess</code>rewrite rule kicks in, mapping the request to a cached file. Anything else is assumed to be context-specific and therefore not cacheable. Note that I use wikipedia-style URI mapping for my blog so <code>/article-23</code> gets mapped to <code>/index.php=article-23</code> when not cached. </p> <p>I use a single HTML access file in my DOCUMENT_ROOT directory and here is the relevant extract. It's the third rewrite rule that does what you want. Any script which generates cacheable O/P wraps this in an <code>ob_start()</code> <code>ob_get_clean()</code> pair and write out the HTML cache file (though this is all handled by my templating engine). Updates also flush the HTML cache directory as necessary.</p> <pre><code>RewriteEngine on RewriteBase / # ... # Handle blog index RewriteRule ^blog/$ blog/index [skip=1] # If the URI maps to a file that exists then stop. This will kill endless loops RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^blog/.* - [last] # If the request is HTML cacheable (a GET to a specific list, with no query params) # the user is not logged on and the HTML cache file exists then use it instead of executing PHP RewriteCond %{HTTP_COOKIE} !blog_user RewriteCond %{REQUEST_METHOD}%{QUERY_STRING} =GET [nocase] RewriteCond %{DOCUMENT_ROOT}/blog/html_cache/$1.html -f RewriteRule ^blog/(article-\d+|index|sitemap.xml|search-\w+|rss-[0-9a-z]*)$ \ blog/html_cache/$1.html [last] # Anything else relating to the blog pass to index.php RewriteRule blog/(.*) blog/index.php?page=$1 [qsappend,last] </code></pre> <p>Hope this helps. My blog describes this in more detail. :-) </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload