I have an Linux web server running WHM/cPanel.
This has a page uploaded in the /public_html folder called compression.php This is accessed with http://www.example.com/compression.php
Within cPanel, in 'Optimize Website', the 'Compress All Content' option is selected and the .htaccess file does have a mod_gzip block - see below:
<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>
Using https://www.whatsmyip.org/http-compression-test/ to test, I can see that the page IS being compressed as expected.
There is a /public_html/public folder which also has a file called compression.php (with slightly different content to differentiate it). When I access this using http://www.example.com/public/compression.php, the page is also compressed.
But, if I want to redirect ALL traffic to the /public_html/public folder in the .htaccess file, I add the following:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Rewrite to 'public' folder
RewriteCond %{HTTP_HOST} ^dev43.360ss.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
</IfModule>
The page in /public loads on the http://www.example.com/compression.php URL & shows the correct content, but it's not compressed any more.
As suggested by cPanel support, I've tried having the mod_gzip block ABOVE the mod_rewrite block in the htaccess.
Because it's compressed without the htaccess redirect, we know gzip is installed & working. And I've tested that the same happens no matter what version of PHP is used (I've tested 7.1, 7.2 & 7.3). I've also tested with php files and an image file - no difference.
Does anyone have any ideas?
Thanks
Turns out, this was the 'Backend Compression' setting in the ModSecurity™ Configuration set to Disabled instead of Enabled!