Fixed issue #17175: t3lib_compressor should write .htaccess to set Expires headers...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_compressor.php
index 83dfb77..4dd316f 100644 (file)
@@ -43,6 +43,14 @@ class t3lib_Compressor {
                // default compression level is -1
        protected $gzipCompressionLevel = -1;
 
+       protected $htaccessTemplate = '<FilesMatch "\.(js|css)(\.gzip)?$">
+       <IfModule mod_expires.c>
+               ExpiresActive on
+               ExpiresDefault "access plus 7 days"
+       </IfModule>
+       FileETag MTime Size
+</FilesMatch>';
+
        /**
         * Constructor
         */
@@ -53,6 +61,15 @@ class t3lib_Compressor {
                        t3lib_div::mkdir(PATH_site . $this->targetDirectory);
                }
 
+                       // if enabled, we check whether we should auto-create the .htaccess file
+               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess']) {
+                               // check whether .htaccess exists
+                       $htaccessPath = PATH_site . $this->targetDirectory . '.htaccess';
+                       if (!file_exists($htaccessPath)) {
+                               t3lib_div::writeFile($htaccessPath, $this->htaccessTemplate);
+                       }
+               }
+
                        // decide whether we should create gzipped versions or not
                $compressionLevel = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['compressionLevel'];
                        // we need zlib for gzencode()