HTTP:accept-encoding gzip - how to?

chuee

Verified User
Joined
Mar 13, 2009
Messages
6
Hi,
I want to serve gzip static html files, but the default seems to ignore them (i get a directory access forbidden), so I tried .htaccess rules:

Code:
#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} (gzip)

#make sure there's no trailing .gz on the url
ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$

#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f

#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [L]

I get the same Forbidden message when using a URL pointing to a directory (i.e looking for an index.html, but only index.html.gz is there); if i specify the file, index.html - then the file is downloaded by the browser.

The code above works on another linux server i use, and I am baffled at the moment. Any suggestions regarding the DirectAdmin set up wrt to gzip file handling, would be received with delight. I am not intending to have dynamic compression; these are static files.
 
Assuming your DA server has been installed with custombuild, your Apache should include DEFLATE and GZIP modules, so you don't have to create .gz version of files: your index.html file (or any other .html file for that matter) should be served compressed automatically. Give it a try.

Forbidden message has nothing to do with that by the way.
If I guess your server configuration correctly the following addition to .htaccess file will fix it:
DirectoryIndex index.html index.htm index.shtml index.php index.php4 index.php3 index.phtml index.cgi index.html.gz

As a side note, may I point out that your rewrite rules do not capture home page URL (http://www.example.com/) and have no effect in this particular case.
 
Hey thanks! To a knowledgeable and alert person. Yes you are right about the capture of home page (index.XXX), and I had wondered if there was a better way. I shall search for a solution.
I have initially tried your suggestion, and i saw nothing delightful in the response headers, or initial browser test. I shall try a few variations of my htaccess. I do recall checking the server modules, and saw no DEFLATE and GZIP modules, so i assumed they weren't using a custom build.

I tried the tool at http://www.dnsqueries.com/en/check_http_gzip.php
which 'checks if a specific web page sends out the correct headers needed to transmit compressed content to the browser', and reported: The 'http server hasn't sent out a "Content-Encoding" header'.
 
Yes you are right about the capture of home page (index.XXX), and I had wondered if there was a better way. I shall search for a solution.
I might be able to help with the correct mod_rewrite rules if you provide more info about your server setup, but I would suggest using it as a last resort. Some browsers have broken implementation of gzip and therefore you can't rely entirely on accept-encoding. Contrary to your custom made setup, Deflate's configuration includes some basics checks to address this issue.

I have initially tried your suggestion, and i saw nothing delightful in the response headers, or initial browser test. I shall try a few variations of my htaccess. I do recall checking the server modules, and saw no DEFLATE and GZIP modules, so i assumed they weren't using a custom build.
You won't find deflate module in Apache's module directory because it should be statically compiled.

If you have a root access to your server, you can check whether
  • Apache is compiled with mod_deflate by executing
    Code:
    httpd -l | grep deflate
  • the server was installed with custombuild by executing
    Code:
    cat /root/.custombuild
    If you don't get an error message "No such file or directory" it means you are using a custombuild.
    Another way of checking it is by looking at the content of /usr/local/directadmin/ directory. It should include custombuild or customapache directory.

I tried the tool at http://www.dnsqueries.com/en/check_http_gzip.php which 'checks if a specific web page sends out the correct headers needed to transmit compressed content to the browser', and reported: The 'http server hasn't sent out a "Content-Encoding" header'.
Such tools should be used with caution because you don't know what "User-agent" value they provide during HTTP/1.1 negotiation.
Like I previously said, some browsers known to have issues with compressed content might be denied gzip encoding even though the server supports it.
For the ultimate check, use curl
Code:
curl --compressed -i --user-agent "Mozilla/5.0 (compatible; Windows NT 5.1; SV1)" 'http://www.example.com' | head -15
and test it with different user-agent values.
 
Last edited:
It's a shame I do not have ssh access on the server.
I am using safari as a browser and it should be good. I assume the issue isn't with Safari as i have found it to work elsewhere. For the DirectAdmin server in question, I switched servers to ssend javascript and css, and they do get sent encoded, with gzip accepted in the response header. I tried with a htaccess stripped of rewrite rules, but same story.
So I conclude I don't have deflate.

Thanks for your kind replies Webcart.
 
Back
Top