diff --git a/boost.admin.htaccess.inc b/boost.admin.htaccess.inc
index 3bebe36..a601afe 100644
--- a/boost.admin.htaccess.inc
+++ b/boost.admin.htaccess.inc
@@ -222,6 +222,13 @@ function boost_admin_htaccess_generate_htaccess() {
     $string .= "  # Allow for alt paths to be set via htaccess rules; allows for cached variants (future mobile support)\n";
     $string .= "  RewriteRule .* - [E=boostpath:$normal_dir]\n";
     $string .= "\n";
+    $string .= "  # Determine whether it is possible to serve compressed content\n";
+    $string .= "  RewriteRule .* - [E=boosttrygzip:0]\n";
+    $string .= "  <IfModule mod_headers.c>\n";
+    $string .= "    RewriteCond %{HTTP:Accept-encoding} gzip\n";
+    $string .= "    RewriteRule .* - [E=boosttrygzip:1]\n";
+    $string .= "  </IfModule>\n";
+    $string .= "\n";
     $string .= "  # Caching for anonymous users\n";
     $string .= "  # Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server" . (variable_get('boost_ssl_bypass', BOOST_SSL_BYPASS) ? " OR https request" : "") . "\n";
     $string .= "  RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]\n";
@@ -234,7 +241,7 @@ function boost_admin_htaccess_generate_htaccess() {
     $string .= "  RewriteRule .* - [S=$skip]\n";
     $string .= "\n";
     $string .= "  # GZIP\n";
-    $string .= "  RewriteCond %{HTTP:Accept-encoding} !gzip\n";
+    $string .= "  RewriteCond %{ENV:boosttrygzip} 0\n";
     $string .= "  RewriteRule .* - [S=$gzip_count]\n";
     $string .= $output['gzip'];
     $string .= "\n";
diff --git a/boost.module b/boost.module
index d4825ad..6e794f9 100644
--- a/boost.module
+++ b/boost.module
@@ -326,8 +326,7 @@ function boost_exit($destination = NULL) {
 
     // Gzip support.
     if (BOOST_GZIP && $_boost['matched_header_info']['gzip']) {
-      // #1416214
-      // boost_write_file($_boost['filename'] . '.gz', gzencode($data, 9));
+      boost_write_file($_boost['filename'] . '.gz', gzencode($data, 9, FORCE_GZIP));
     }
   }
 }
@@ -1537,6 +1536,14 @@ function boost_htaccess_cache_dir_generate() {
     $string .= "</FilesMatch>\n";
   }
 
+  // Set proper headers when serving compressed content
+  $string .= "<IfModule mod_headers.c>\n";
+  $string .= "  <FilesMatch \"\.gz$\">\n";
+  $string .= "    Header set Content-Encoding gzip\n";
+  $string .= "    Header append Vary Accept-Encoding\n";
+  $string .= "  </FilesMatch>\n";
+  $string .= "</IfModule>\n";
+
   // Make sure files can not execute in the cache dir.
   $string .= "\n";
   $string .= "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\n";
