gzip working but YSlow indicates it's not - .htaccess

I'm getting used to Firebug and YSlow in particular. One of the things I'm looking at is the gzip compression. YSlow still gives my site an "F" and indicates that my CSS and JavaScript files are not being compressed.
However, if I run an external gzip test against my site (such as http://www.gidnetwork.com/tools/gzip-test.php) it tells me that gzip is working and gives me my savings, although I think this may just be the HTML.
This is the relevant section of my .htaccess file:
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.(html?|txt|js|php|pl|jpg|png|gif)$
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>
Why does YSlow not agree with the external gzip test?

mod_gzip is an obsolete part of Apache 1.x, having been replaced by mod_deflate in Apache 2.
This mod_deflate configuration makes YSlow happy here:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/css text/html text/plain text/xml
DeflateCompressionLevel 9
</IfModule>
The only reason there are two AddOutputFilterByType lines is to avoid horizontal scrolling.

Not measuring behind a proxy? My work proxy screws with my yslow results...!

Just add the next code to your .htaccess
# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP
Seems it makes both GTmetrix & Yslow happy
Don't forget to add
ob_start("ob_gzhandler");
at the beginning of your header file if your are using PHP

Related

Joomla Gzip Compression worked just in Homepage

in my Joomla3 Website, when I enabled Gzip(from Global config , Cpanel Optimize website , .htaccess) , worked as well but just in one page(Homepage) .
Why does this happen?
php.ini
zlib.output_compression = On
zlib.output_compression_level = 9
.htaccess
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/font
AddOutputFilterByType DEFLATE application/font-truetype
AddOutputFilterByType DEFLATE application/font-ttf
AddOutputFilterByType DEFLATE application/font-otf
AddOutputFilterByType DEFLATE application/font-opentype
AddOutputFilterByType DEFLATE application/font-woff
AddOutputFilterByType DEFLATE application/font-woff2
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/woff
AddOutputFilterByType DEFLATE font/woff2
</IfModule>
## END EXPIRES CACHING - JCH OPTIMIZE
<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 mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>
I started to look at my security and firewall plugins. Specifically, ModSecurity – an application for Web Hosting Manager that helps prevent attacks on your web server. It is a great firewall application and a must have if you are running WHM in my opinion. Interestingly enough, I noticed that if I disabled the Rules Processing engine compression, would work WITH pretty permalinks. This led me to where the rules came from. Which happens to be Pxysoft Anti Malware, another great plugin which I plan to review later. So I went through the rules directives located in the file modsec2.antimalware.conf (where the rules came from). I started commenting out every option and rule and then toggling the rules engine on and off – one by one. I did this by connecting via SSH. Which if you’re not familiar with, you really should read in-depth tutorials before messing around. Anyways, I came across the option SecDisableBackendCompression On and commented it out. After restarting the rules engine, gzip worked on all URLs! Finally!

Not able to redirect old domain to new domain in .htaccess file

Hi I'm trying to redirect old url to a new url through htaccess file but it's not working i have other scripts also running in the file
I tried other scripts of redirecting url but still doesn't work, i don't know what could be the issue but i was thinking maybe it could be because of the script is not in the order where it should be, so can anybody help me with this. and thanks in advance
.htaccess File Redirect is in line 3
AddType 'text/html; charset=UTF-8' html
RewriteEngine On
Redirect /old-domain.com https://new-domain.com
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://new-domain.com/$1 [L,R=301]
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<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 mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>
Redirect /old-domain.com https://new-domain.com makes no sense at all, it attempts to rewrite a folder "old-domain.com" which is not what you want. I really suggest that you take a look into the documentation of the tools you use. It it is excellent quality and comes with great examples...
Instead take a look at this approach using the rewriting module:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$
RewriteRule ^/?(.*)$ https://new-domain.com/$1 [R=301]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
This implementation will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

Enable Text Compression for a URL without file extension .htaccess

I am trying to solve the "Enable Text Compression" opportunity on the new Lighthouse page speed audits and am wondering how to enable text compression for a url like below:
www.magento2.com/customer/section/load?sections=&update_sectionid=false&_=12345678
I'm hoping there is a way to do this with .htaccess however there is no .txt appended so am unsure how I can apply to this controller that is generating a JSON response.
I've tried adding to my gzip configuration:
mod_gzip_item_include mime ^application/json.*
However above does not seem to work.
I have also tried adding below to my VHOST in order to try and force the type:
<Location "/customer/section">
ForceType application/json
</Location>
This however is not seeming to kick the compression into action. The response headers do show content-type: application/json so feel that Gzip should recognise this as a type of response that should be compressed.
My current gzip compression is set as below within .htaccess:
<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_include mime ^application/json.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
Where i have tried to enable by type however would like some other ideas on how this could be achieved?
Using mod deflate instead with below config just worked for me in the end:
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
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
AddOutputFilterByType DEFLATE application/json
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
</IfModule>

My .htaccess file might be incorrect

I am creating a .htaccess file that will compress my website. I copied and pasted the gzip code but when I tested the website it did not compress.
I placed my .htaccess file in the public/html directory along with other web pages, and I made sure to change the file name from the original txt file.
Here is the code from the .htaccess file
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 504 /504.html
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4 .doc
# disable directory browsing
Options All -Indexes
<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
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>
first thing first, make sure your apache has mod_gzip or mod_deflate loaded
run this and check it
print_r(apache_get_modules());
note: for apache 2+ you need mod_deflate, for earlier versions mod_gzip (you may need to alter your htaccess file in that case)

getting error 500 when trying to use gzip with .htaccess

I'm trying to use gzip on my site.
I'm trying to compress, php, css and js files. The server is apache 1.3, and the code I have in the .htaccess file is:
# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
But when I upload this, I just get an Error 500 page.
Any ideas.
Try this
<Files *>
#Compress
SetOutputFilter GZIP
</Files>
Or this
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
AddOutputFilterByType doesn't appear to be available on Apache 1.3 (src). I believe you'll need to use mod_gzip instead.
"Compatibility: Available in Apache 2.0.33 and later; deprecated in Apache 2.1 and later"

Resources