How can I make my server use gzip compression? - apache

I'd like to make my server apply gzip compression to html, php, javascript and css files.
I think I can do it by editing the .htaccess file. Can someone give me the exact code that I would have to add?
Also, if I add the appropriate code to an .htaccess file in the parent directory, does it automatically apply to all sub-directories too? For instance, if I have http://domain1.com pointed at my root directory and http://domain2.com pointed at a sub-directory, will the second domain provide compressed files without me needing to edit the .htaccess file in that directory too?
Thanks

Use mod_deflate
More info here: http://httpd.apache.org/docs/2.2/mod/mod_deflate.html

From the document that Peter Hall referenced on mod_deflate:
AddOutputFilterByType DEFLATE text/html text/css text/plain text/javascript application/javascript
And I believe that the answer is "yes" about the setting propagating down the directory tree to subdirectories. The best thing to do is check the response headers from the site (using FireBug or similar tool where you can watch the network traffic) and verify that the contents are compressed.

Related

How to modify Content-Type in apache

We are currently having Content-Type: text/html.
We want to modify this to text/javascript or text/css.
We have tried this using rewrite rule, mod_headers and also through mod_mime, but we are unable to modify it.
Any suggestion?
Assuming you have certain text files in a directory say styles add a .htaccess file in the root directory and add the following content:
<Location /styles>
ForceType text/css
</Location>
And use the similar concept for javascript as well
I had solved this by changing the content type in application servers of content.

What configuration is responsible for a working deflate / gzip?

I had a look in my (standard configurated) httpd.conf on my Apache 2.2 webserver and I was not able to identify what configuration is responsibly that gzip compression is working fine?
I searched for keywords like DEFLATE, AddOutputFilterByType or mod_deflate. But none of these keywords are in my httpd.conf.
Can anyone tell me, why compression works fine with the standard configuration? What configuration line is responsible for that?
You're looking for exactly the right thing, but you're probably not looking in all of your configuration files. You're probably using a multi-file layout, or looking in the complete wrong file.
Try looking for Include, or load mod_info to review the config that way in merged form.
I found the solution: A mod_deflate code in my .htaccess file in a subdirectory on my WordPress blog (Plugin WPSuperCache and Autoptimize) were responsible for the working gzip compression.

Apache AddType text/css .css Ignored

I have made an ,htaccess file in my /font directory with only this line in it (as part of troubleshooting).
AddType text/css .css
None the less Google Chrome (even 19.0.1053.0 canary) reports that the .css files are returned as: MIME type text/html
http://paulanorman.com/:11 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://paulanorman.com/fonts/iwona-stylesheet.css".
I use Hostgator and have checked in Cpanel that text/css is default on my server for .css
I have also checked using wget on cygwin bash shell and the documents are indeed coming down as text/html
These stylesheets are being ignored. However I have found if I
<style ..>
<?php include "dah dha / style-sheets.css" ?>
</style>
one by one in the head of my document all is fine.
However I would like not to have to do that.
Any one solved this? I have read much all over the net about this and it appears as an unexplained fickle problem it seems.
TIA
paul
According to www.askapache.com this is ok as a one step process with the quote marks
AddType 'text/css; charset=UTF-8' css

How to add Header Content-type to static pages which doesn't have extensions?

I have a XML page www.example.com/page, but my server outputs it as text/plain as it doesn't have any extension.
So I want to add XML Header via .htaccess to all the files which doesn't have extension with a condition that the file exists.
As if file doesn't exist, program is executed from database and it decides what header to output, so I don't want to break that part by forcibly changing header.
Add a DefaultType text/xml (or whatever type you're using for your XML) to your .htaccess.
Other command you can put in your .htaccess (but it will force all files to have this content-type):
ForceType text/xml
http://httpd.apache.org/docs/1.3/mod/mod_mime.html#forcetype

Apache2 won't Gzip my js/css

My server doesn't seem to gzip my css and javascript files. It works for HTML.
Here's my config: http://pastie.org/1105941
And here's my result: http://i35.tinypic.com/audv0k.jpg
Also tested Google Page Speed, and made Apache2 log the compression results. They say the same.
What could be wrong here, since it does compress the HTML?
As far as I can see, it is working ... using firefox and the webdeveloper plugin the response for both css and js reports gzip
Download a CSS file with a browers and check the content type. Chances are that it's application/binary or something. If that is the case, you must tell the server that *.css should be sent as text/css, etc:
AddType text/css .css