skip to Main Content

If I include the following in my .htaccess, GZIP will only compress files when the full path to the file is specified:

RewriteRule ^ index.php [L]

But the above rewrite is necessary to allow my CMS to function.

So for example:

https://karenkingston.co.uk isn’t compressed, but https://karenkingston.co.uk/index.php is, and indeed https://karenkingston.co.uk/themes/coach/js/jquery.scripts.js also compresses.

PHP 7.2 but changing versions doesn’t help. Nor does it help to enable GZIP from .htaccess vs. CPanel.

Here’s the full .htaccess

Options -indexes

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

AddType application/vnd.ms-fontobject .eot 
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType application/x-font-woff2 .woff2
AddType image/svg+xml .svg

ExpiresActive on
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType application/x-font-woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/x-javascript "access plus 1 year"
ExpiresByType application/pdf "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 month"

ErrorDocument 404 /

Redirect 301 /home https://karenkingston.co.uk
Redirect 301 /search https://karenkingston.co.uk

Any ideas?

2

Answers


  1. the above code doesn’t enable gzip use below code

    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>
    
    Login or Signup to reply.
  2. do this in your .htaccess file

    # compress text, html, javascript, css, xml:
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xmlin
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    # Or, compress certain file types by extension:
    <files *.html>
    SetOutputFilter DEFLATE
    </files>
    

    then in your php

    <?php
       if (substr_count($_SERVER[‘HTTP_ACCEPT_ENCODING’], ‘gzip’))
       ob_start(“ob_gzhandler”);
       else ob_start();
    ?>
    

    write the above php code in a file that is always active such as your config file or your index.php file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search