GZip enabled on starka?

wolf99

Member
Messages
38
Reaction score
0
Points
6
so basically, the answer is no, use PHP, yeah?

can you tell me, is correct usage:

PHP:
<?php

ob_start("ob_gzhandler");

?>
<html>
<body>
<p>This should be a compressed page.</p>
</html>
<body>

thanks

EDIT: how can this be applied in the case of non .phph files? for eg. font files for @font-face?
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You could write a script that does nothing but output another file. For example,
PHP:
<?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.
 
Last edited:
Top