GZip files with .htaccess and PHP that works with Wordpress
Published May 7th, 2009 in Scripts, Tips and Tricks, Wordpress
Lately, I have been burning through bandwidth. I had thought that I have enabled all possible tweaks until I discovered that there is an additional work-a-round that will use gzip compression for PHP, CSS, and JS files.
While there are more simplified solutions for use, Wordpress installations create additional obstacles that this code addresses well. The results may be measured using YSlow a plugin for Firefox or Rex Swain's HTTP Viewer. In my case, the file sizes were reduced by half for most pages.
I had tried several possible suggestions posted throughout the internet community until I found a solution that actually worked for me. For Wordpress installations this solution works great as there are CSS and JS files throughout the installation.
Create a file called gzip.php and put in the root folder where Wordpress is installed.
<?php
if(isset($_SERVER['HTTP_ACCEPT_ENCODING']) && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start('ob_gzhandler');
else
ob_start();
?>
Then append to .htaccess
################## GZip Files ################### <FilesMatch "\.js$"> AddHandler application/x-httpd-php .js php_value default_mimetype "text/javascript" </FilesMatch> <FilesMatch "\.css$"> AddHandler application/x-httpd-php .css php_value default_mimetype "text/css" </FilesMatch> <FilesMatch "\.(htm|html|shtml)$"> AddHandler application/x-httpd-php .html php_value default_mimetype "text/html" </FilesMatch> php_value auto_prepend_file /absolute/path/to/gzip.php
Print This Post
Email This Post
Related Articles
- RHEL Logrotate Apache Logs Daily with Compression
- WinZip 9.0 SR1 repack for silent installation
- WordPress Pretty Permalinks on IIS without mod rewrite
- Combine multiple installations of Wordpress into the same MySQL database.
- WordPress Permalinks will not work in a default XAMMP installation



One Response to “GZip files with .htaccess and PHP that works with Wordpress”
Please Wait
Leave a Reply
You must log in to post a comment.