WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] XHTML to HTML plus gzip compression? (2 posts)

  1. Funkphenomenon
    Member
    Posted 7 years ago #

    I used Matt's solution in topic 16804 to turn WP's XHTML into HTML.

    This works fine, but it conflicts when I turn on WP's gzip compression:

    Warning: ob_start(): output handler 'ob_gzhandler' cannot be used twice (...)

    I also tried adding some lines in .htaccess to turn on gzip compression:

    <FilesMatch ".(php|html?)$">
    php_value zlib.output_compression 4096
    </FilesMatch>

    I had the impression this had worked before, but apparently it doesn't work (anymore?) for some reason: no compressed files (XHTML to HTML works fine). Adding the following code also didn't work:

    <?php ob_start( 'ob_gzhandler' ); ?>

    Is there a way to compress my PHP and HTML files, while still converting XHTML to HTML?

  2. Funkphenomenon
    Member
    Posted 7 years ago #

    To apply gzip-compression AND convert XHTML to HTML, someone at another forum gave me the following code:

    <?php
    function make_html($page) {
    if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")!==false) {
    header("Content-Encoding: gzip");
    return gzencode(str_replace(' />', '>', $page));
    } else {
    return str_replace(' />', '>', $page);
    }
    }
    ob_start('make_html');
    ?>

    This works like a charm!

Topic Closed

This topic has been closed to new replies.

About this Topic