Forum Moderators: phranque

Message Too Old, No Replies

AddEncoding x-gzip .css blanks CSS files?

I just want to compress CSS and other file types using Apache 1.3

         

JAB Creations

3:27 am on Jun 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've been trying to find out how to compress files by type for Apache 1.3 but I am mostly seeing 2.0 documentation. Went to Apache's site at this url for example...
[httpd.apache.org...]

I tried this in my .htaccess file...

AddEncoding x-gzip .css

Not sure if that is how the syntax should look and I would please like some help clarifying how I should do this. I also came across issues regarding backwards compatibility. I'm server for Gecko 1.0+, IE 5.0+, and Opera 4.0+ (none of these require XHTML cloaking, just extra CSS includes) on the PC platform in case there are any issues I need to be made aware of with those browsers/version as far as handling compression is concerned. However I'm not worried about browsers outside that range on the PC platform. Thanks!

- John

jdMorgan

3:56 am on Jun 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've been experimenting with this MIME-type stuff recently, too.

Generally, you need to make sure the client can accept gzip encoding by checking the HTTP_ACCEPT_ENCODING header. If the client says it can accept the compressed format, then serve (rewrite to) stylesheet.css.gz instead of serving stylesheet.css.

Basically,


RewriteCond %{HTTP_ACCEPT_ENCODING} gzip
RewriteRule ^(([^.]+\.)+)css$ /$1css.gz [L]

Then mark only .gz files with the application/x-gzip MIME-type, and leave .css files as text/plain.

Remember that the AddType directive works off the served filetype, so if you rewrite to stylesheet.css.gz, the URL is /stylesheet.css, the filename is stylesheet.css.gz, and the MIME type is application/x-gzip. If you don't do the rewrite, then the URL is /stylesheet.css, the filename is stylesheet.css and the MIME type is text/plain.

Jim

JAB Creations

5:28 am on Jun 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you very much Jim, though unfortunately this breaks Apache 2 (which I test with locally) and did not seem to have any effect on my live server which runs Apache 1.3x from what I observed? Should this only work on 1.3x?

- John

jdMorgan

1:50 am on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, I didn't test that specific code. How did it "break" on Apache 2.0? -- Was the variable undefined, or was there some other problem?

Jim

JAB Creations

2:23 am on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just get an error 500. Is there a string I can use in .htaccess to give a more meaningful error message to help solve the issue? Thank you for your response.

- John

jdMorgan

2:43 am on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Meaningful error messages are logged in the server error log. Correlating that info (by timestamp) with the access log often nails down the problem pretty thoroughly.

Jim

JAB Creations

4:36 am on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok *duh* LoL, here we go...

[Tue Jun 12 00:33:38 2007] [alert] [client 127.0.0.1]?:/../../../.htaccess: Invalid command 'RewriteCond', perhaps misspelled or defined by a module not included in the server configuration, referer: [localhost...]

I'm running XAMPP and I haven't modified anything except for the path to the public folder.

- John

jdMorgan

4:51 am on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mod_rewrite is not installed or not loaded, then...

Look for AddModule and LoadModule directives referring to mod_rewrite.so and uncomment them if they're commented-out.

Jim