Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Setting cache with htaccess


jdMorgan - 2:45 am on Aug 12, 2004 (gmt 0)


> I have to use a software (script) based cache system to have my pages cached for everybody.

To have your server serve a "cached" file if available, and call your script to generate a new file if a cached version is not already available, you have to use a script, yes. That script can be built into your existing one, or you can write another one. You could do it in .htaccess, PERL, PHP, or several other scripting languages.

It boils down to:

  • Check for existence of requested page
  • If it exists, serve it
  • If not regenerate it by calling your original dynamic page generation script

    This could be as simple as something like this in .htaccess using mod_rewrite:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(page_name)\.html$ /script.php?page=$1 [L]

    and the only change needed to your existing script is to save its output to a file called "page_name.html" in addition to sending it back to the client as it does now. You would also need to come up with a plan to delete these "cached" pages periodically or whenever their contents are updated, in order to let the script generate the new version.

    The above code is meant only as an example only, so please take it as such.

    Jim


    Thread source:: http://www.webmasterworld.com/apache/1922.htm
    Brought to you by WebmasterWorld: http://www.webmasterworld.com