Article Sidebar apr2006.tar

mod_rewrite config roundup

Besides the presence of query-string parameters, there are other conditions by which a page should be left dynamic. The WebStatistics page and the WebIndex belong to this category. We can extend the first rewrite rules to tell Apache to avoid these pages. Thus, the production Apache caching configuration (together with the usual directory statements) looks as follows:

RewriteEngine   On
RewriteLogLevel 0
RewriteLog      /var/log/apache/port-80/rewrite.log
RewriteLock     /var/log/apache/port-80/rewrite.lock

RewriteMap  generator      prg:/var/www/twiki/bin/ \
                               content-cache-generator.pl
RewriteMap  remover        prg:/var/www/twiki/bin/ \
                               content-cache-remover.pl

RewriteRule !/twiki/bin/(view|save)/         -  [last]

RewriteCond %{QUERY_STRING}     !^$             [OR]
RewriteCond %{REQUEST_FILENAME} WebStatistics   [OR]
RewriteCond %{REQUEST_FILENAME} WebIndex        [OR]
RewriteCond %{REQUEST_FILENAME} WebChanges      [OR]
RewriteCond %{REQUEST_FILENAME} TWikiUsers
RewriteRule .         -         [last]

RewriteRule /twiki/bin/(view|save)/(.*)/(.*)$  -  \
  [ENV=TWIKIWEB:$2,ENV=TWIKIPAGE:$3]

RewriteCond \
  /var/www/twiki/cache/%{ENV:TWIKIWEB}.%{ENV:TWIKIPAGE}.html   -s
RewriteRule /twiki/bin/view/  \
  /twiki/cache/%{ENV:TWIKIWEB}.%{ENV:TWIKIPAGE}.html [last]

RewriteRule /twiki/bin/view/  \
  ${generator:%{ENV:TWIKIWEB}/%{ENV:TWIKIPAGE}} [last]

RewriteRule /twiki/bin/save/  \
  /twiki/bin/save/${remover:%{ENV:TWIKIWEB}/%{ENV:TWIKIPAGE}} [last]

DocumentRoot /var/www/

<Directory />
        Options FollowSymLinks
        AllowOverride None
</Directory>

<Directory /var/www/twiki/cache/>
        Header add Pragma no-cache
</Directory>