You could write a script that does nothing but output another file. For example,
PHP Code:
<?php
ob_start('ob_gzhandler');
// init.php does useful things like set the include path
include_once($_SERVER['DOCUMENT_ROOT'] . '/init.php');
// You'll need to write the sanitize function so that users can't view arbitrary files
$file = sanitize($_REQUEST['path']);
if (file_exists($file)) {
$type = content_type($file);
header('Content-type: ' . $type);
// output any other headers you want to send
if (strpos($type, 'text/') == 0) {
// as another safety feature, use a sub-request to fetch any 'text/*' files,
// in case the file is a script. You could write a more restrictive test to skip
// files that aren't scripts.
virtual($_REQUEST['path']));
} else {
readfile($file);
}
} else {
header('HTTP/1.0 404 Not Found');
// or wherever your custom 404 doc is located
include('errordocs/404.php');
}
Redirect URLs for allowed types through the compression script. As the last rewrite rule in your top-level .htaccess, put:
Code:
RewriteRule ^/?(.*\.(html|css|js|png|gif|jpg))$ /path/to/gz.php?path=/$1 [QSA,NS]
Note that this will circumvent any rewrite rules in subdirectories.