We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36582
    • 463 Posts
    Modx 2.5.1 and PHP 5.6 (1and1) - the following in root .htaccess file is causing the manager to break - white-screen. compress_js on or off makes no difference. Any ideas? I'm trying to speed the site up and this is the only way of serving compressed files via 1and1 shared hosting. My thinking is that somehow I need to exclude the manager directory from being affected by this.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*\.js) gzip.php?type=js&file=$1
    RewriteRule ^(.*\.css) gzip.php?type=css&file=$1
    </IfModule>


    The code in the referenced gzip.php is as follows...

    <?php
    //check that zlib compression is enabled
    if(!ini_get('zlib.output_compression')){ die(); }
     
    $allowed = array('css','js'); //set array of allowed file types to prevent abuse
     
    //check for request variable existence and that file type is allowed
    if(isset($_GET['file']) && isset($_GET['type']) && in_array(substr($_GET['file'],strrpos($_GET['file'],'.')+1), $allowed)){
    	$data = file_get_contents(dirname(__FILE__).'/'.$_GET['file']); // grab the file contents
     
    	$etag = '"'.md5($data).'"'; // generate a file Etag
    	header('Etag: '.$etag); // output the Etag in the header
     
    	// output the content-type header for each file type
    	switch ($_GET['type']) {
    		case 'css':
    			header ("Content-Type: text/css; charset: UTF-8");
    		break;
     
    		case 'js':
    			header ("Content-Type: text/javascript; charset: UTF-8");
    		break;
    	}
     
    	header('Cache-Control: max-age=300, must-revalidate'); //output the cache-control header
    	$offset = 60 * 60;
    	$expires = 'Expires: ' . gmdate('D, d M Y H:i:s',time() + $offset) . ' GMT'; // set the expires header to be 1 hour in the future
    	header($expires); // output the expires header
     
    	// check the Etag the browser already has for the file and only serve the file if it is different
    	if ($etag == $_SERVER['HTTP_IF_NONE_MATCH']) {
    		header('HTTP/1.1 304 Not Modified');
    		header('Content-Length: 0');
    	} else {
    		echo $data;
    	}
    }
    ?>

    This question has been answered by chrisandy. See the first response.

      Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk
    • discuss.answer
      • 36582
      • 463 Posts
      Ok - a little more thought and I found the answer with a rewrite condition to isolate just the assets folder...

      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_URI} ^/(assets)
      RewriteRule ^(.*\.js) gzip.php?type=js&file=$1
      RewriteRule ^(.*\.css) gzip.php?type=css&file=$1
      </IfModule>
        Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk