Enable mod_deflate - apache

I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code in my .htaccess file:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
It did not compress any of my files when I tested my site in firebug. What am I doing wrong?

As this'll be moved to SF soon, Shouldn't it be:
<FilesMatch "\.(js|css|html|htm|php|xml)$">
Otherwise the regex becomes \.js, for example (because you've escaped the '\').

SetOutputFilter DEFLATE
I used this and it worked. It was an internet history problem. My yahoo Yslow was saving the results from the first check so when I modified the htaccess the difference did not show up.

Related

How to disable gzip compression in htaccess for a folder

I am looking to disable the gzip folder for folder xxx. looking in StackOverflow, I have tried this :
SetEnvIf Request_URI ^/xxx(.*) no-gzip dont-vary
But it doesn't work.
I have added in here :
<IfModule mod_deflate.c>
SetEnvIf Request_URI ^/flipbook(.*) no-gzip dont-vary
# enables the filter
SetOutputFilter DEFLATE
# non-textual entities should be already compressed
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
and even outside the mod_deflate module but nothing works.
Could anyone help?
SetEnvIf Request_URI ^/flipbook(.*) no-gzip dont-vary
This looks like it should work - for any URL that starts /flipbook (case-sensitive). Setting the no-gzip environment variable disables the DEFLATE filter of mod_deflate.
However, the (.*) part on the regex is entirely superfluous. And, unless you are specifically using the dont-vary env var in your own directives then this isn't doing anything. I don't think dont-vary is a "special" Apache env var. Apache has force-no-vary, which does what dont-vary is probably intended to do, however, I don't believe you should be disabling the Vary header anyway since mod_deflate applies the filter based on the Accept-Encoding HTTP request header sent from the client, so any intermediary caching proxies should cache based on this header. (Only certain proxies have a problem with this header.)
So, this should be written:
SetEnvIf Request_URI "^/flipbook" no-gzip
Reference:
https://httpd.apache.org/docs/2.4/env.html#special
# enables the filter
SetOutputFilter DEFLATE
This doesn't just "enable the filter", it enables the DEFLATE filter on all responses. This basically renders the AddOutputFilterByType directives that follow superfluous, since you are already setting DEFLATE on everything. Generally, you don't want to set it on everything, which is presumably why you are using the AddOutputFilterByType directives.
So, you probably don't need the SetOutputFilter directive, if you are setting the DEFLATE on specific mime-types. OR, you use SetOutputFilter and remove the AddOutputFilterByType directives, but then you should still disable the filter on images and other already compressed media using the no-gzip env var.
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
You don't need all 3. Your server is setting just one mime-type when sending JavaScript files - which you can see in the HTTP response. You only need that one. (Probably application/javascript.)
Alternative solution
Instead of setting the no-gzip env var to disable mod_default, you could instead use an Apache <If> expression to conditionally set the output filters only when not accessing URLs that start /flipbook.
For example:
<If "%{REQUEST_URI} !~ m#^/flipbook/#">
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/javascript
</If>
You don't really need the <IfModule> wrapper unless you intend to port the same code to multiple servers where mod_deflate might not be enabled (and that is acceptable).

mod_deflate disabled: assets still being gzipped

When I execute:
sudo a2dismod deflate
sudo service apache2 restart
And refresh & inspect the response headers of my site in Chrome Web Tools, my assets (css and js) are still being marked as Content-Encoding : gzip. Y-Slow also confirms that all assets except the actual html document are still compressed.
I have output compression turned off in CodeIgniter's config file:
$config['compress_output'] = FALSE;
For what it's worth... though with the deflate module disabled I don't think it matters much, my /etc/apache2/mods-available/deflate.conf file is the system default:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
</IfModule>
I'm running Ubuntu 12.04. What else could be causing my assets to be compressed?
My .htaccess file is void of deflate commands.
You can try the following.
to disable the gzip for a specified file try this:
SetEnvIfNoCase Request_URI YOUR_FILE_NAME\.php$ no-gzip dont-vary
in you htaccess file. change YOUR_FILE_NAME\.PHP$ to what you need.
and to disable the gzip at all try this:
SetEnv no-gzip dont-vary
in your htaccess file.

127.0.0.1/asd does'not work on ubuntu environment

I was working on microsoft environment, but now I moved my website to ubuntu, the problem is, when I try to write a link like this, 127.0.0.1/asd, I get not found error, the thing that makes me crazy is, that URL sometimes work sometimes does not work and It was working great on windows environment, this is the error I get,
Not Found The requested URL /asd was not found on this server.
this is my .htaccess,
# 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>
RewriteEngine On
RewriteRule ^([//a-zA-Z0-9_-]+)$ tab.php?tab_id=$1 [QSA,L]
Your problem seems to be your rewrite rule - "//" should be "\/" - what does your apache conf file look like, does it have .htaccess enabled for that directory?

How can I get Apache gzip compression to work?

I can't get my site to use gzip compression.
I recently watched this video by Chris Coyier over at css-tricks.com. In the video, he talks about enabling gzip compression to make websites run faster.
As per his instruction, I linked through to github via html5boilerplate.com, copied the gzip compression code from their .htaccess file, pasted it into my own, and uploaded it to my site.
I've tested it via gzipwtf.com and it doesn't seem to work. Can anyone help me with this?
My .htaccess file looks like this:
# ----------------------------------------------------------------------
# Trim www
# ----------------------------------------------------------------------
RewriteEngine On
RewriteCond %{HTTP_HOST} !^orbitprint.com$ [NC]
RewriteRule ^(.*)$ http://orbitprint.com/$1 [L,R=301]
# ----------------------------------------------------------------------
# Gzip compression
# ----------------------------------------------------------------------
<IfModule mod_deflate.c>
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
Try this :
####################
# GZIP COMPRESSION #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
It is better to implement it as in the snippet below.
Just paste the content below in your .htaccess file, then, check the performance using: Google PageSpeed, Pingdom Tools and GTmetrics.
# Enable GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType image/gif "access plus 2678400 seconds"
ExpiresByType image/jpeg "access plus 2678400 seconds"
ExpiresByType image/png "access plus 2678400 seconds"
ExpiresByType text/css "access plus 518400 seconds"
ExpiresByType text/javascript "access plus 2678400 seconds"
ExpiresByType application/x-javascript "access plus 2678400 seconds"
</ifmodule>
# Cache Headers
<ifmodule mod_headers.c>
# Cache specified files for 31 days
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
# Cache HTML files for a couple hours
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
# Cache PDFs for a day
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
# Cache Javascripts for 31 days
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</ifmodule>
Your .htaccess should run just fine; it depends on four different Apache modules (one per each <IfModule> directive). I guess one of the following:
your Apache server doesn't have either mod_filter, mod_deflate, mod_headers and/or mod_setenvif modules installed and running. If you can access the server config, please check /etc/apache2/httpd.conf (and the related Apache config files); otherwise, you can see which modules are loaded via phpinfo(), under the apache2handler section (see attached image); (EDIT) OR, you can open a terminal window and issue the command sudo apachectl -M that will list the loaded modules;
if you get an http 500 internal server error, your server may not be allowed to use .htaccess files;
you are trying to load a PHP file that sends its own headers (overwriting Apache'sheaders), thus "confusing" the browser.
In any case, you should double-check your server config and error logs to see what's going wrong. Just to be sure, try to use the fastest way suggested here in Apache docs:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
and then try to load a large textfile (preferably, clean your cache first).
(EDIT) If the needed modules are there (in the Apache modules dir) but aren't loaded,
just edit /etc/apache2/httpd.conf and add a LoadModule directive for each one of them.
If the needed modules aren't there (neither loaded, nor in the Apache modules directory), I fear that the only option is reinstalling Apache (a complete version).
First of all go to apache/bin/conf/httpd.conf and make sure that mod_deflate.so is enabled.
Then go to the .htaccess file and add this line:
SetOutputFilter DEFLATE
This should output all the content served as gzipped, i have tried it and it works.
Ran into this problem using the same .htaccess configuration. I realized that my server was serving javascript files as text/javascript instead of application/javascript. Once I added text/javascript to the AddOutputFilterByType declaration, gzip started working.
As to why javascript was being served as text/javascript: there was an AddType 'text/javascript' js declaration at the top of my root .htaccess file. After removing it (it had been added in error), javascript starting serving as application/javascript.
In my case i have used following code for enabling gzip compression in apache web server.
# Compress HTML File, CSS File, JavaScript File, Text File, XML File and Fonts
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/x-httpd-php
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 font/otf
AddOutputFilterByType DEFLATE font/ttf
I have taken reference from http://www.tutsway.com/enable-gzip-compression-using-htacess.php.
If your Web Host is through C Panel Enable G ZIP Compression on Apache C Panel
Go to CPanel and check for software tab.
Previously Optimize website used to work but now a new option is available i.e "MultiPHP INI Editor".
Select the domain name you want to compress.
Scroll down to bottom until you find zip output compression and enable it.
Now check again for the G ZIP Compression.
You can follow the video tutorial also. https://www.youtube.com/watch?v=o0UDmcpGlZI
In my case append only this line worked
SetOutputFilter DEFLATE
Enable compression via .htaccess
For most people reading this, compression is enabled by adding some code to a file called .htaccess on their web host/server. This means going to the file manager (or wherever you go to add or upload files) on your webhost.
The .htaccess file controls many important things for your site.
The code below should be added to your .htaccess file...
<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>
Save the .htaccess file and then refresh your webpage.
Check to see if your compression is working using the Gzip compression tool.
<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>
<IfModule mod_deflate.c>
# Insert filters
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/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

How to enable GZip compression in Zend Server CE

I work with Falsh buider and httpserver.
To accelerate result display, I'd like to activate compression on Zend Server.
I create .htaccess on /usr/local/zend/apache2/htdocs/, like this:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
I restart zend server, but compression seems to be desable.
Indeed on log, file size is the with compression and without.
So can you help me to solve that.
Thanks
You may need to add
AddOutputFilterByType DEFLATE application/x-amf
since you may be indicating that you are using Flash remoting
According your comment, I modify httpd.conf like that:
LoadModule deflate_module modules/mod_deflate.so
<Location />
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/xml application/xml application/x-amf
</IfModule>
</Location>
Now delate_module is loaded.
But when I launch httpservice from flex with e4X resultformat, result file has same size that without compression, Why?
Thanks for helping