Forum Moderators: phranque

Message Too Old, No Replies

htaccess problem

Need it to redirect on accept encoding !gzip

         

jetteroheller

12:14 pm on Mar 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My provider does not like to install the perfect solution for the tastk: mod_gunzip

So I have to work with a redirect to a script, if the client does not support compressed delivery

RewriteCond %{HTTP:accept-encoding} !gzip
RewriteRule .*.(htm¦js)$ http://example.com/cgi-bin/inflate.pl?file=$1 [r=307,L]

This should mean, if accept endoding !gzip
redirect all *.htm or *.js files
to a cgi script
the parameter file contains the part of the URL past the domain name

so

http://example.com/test/this.htm

should be redirected to

http://example.com/cgi-bin/inflate.pl?file=/test/this.htm

But something is maybe wrong with my .htaccess

It's difficult to test, so I use a server speed test
to find out, does it work or not.

Most server speed tests do not support compressed delivery.
So they are ideal to test.

jdMorgan

1:45 pm on Mar 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> the parameter file contains the part of the URL past the domain name

As written, the value passed for "file=" would contain only the file extension "htm" or "js" because those are the only parts of the requested URL-path enclosed within the first set of parentheses. Try:


RewriteCond %{HTTP:Accept-Encoding} !gzip
RewriteRule ^(.+\.(htm¦js))$ http://example.com/cgi-bin/inflate.pl?file=$1 [R=307,L]

The value passed as "file=" will now be the entire localized URL-path, e.g. "test/this.htm"

I also suggest that you do *not* feel at liberty to change the case on variables, directives, or flags until you know that the code works with proper casing.

Further, when you get this working, I'd suggest using an internal rewrite instead of a redirect. There is no reason to expose the "cgi-bin/inflate.php" filepath to the client -- browser or robot.

Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe characters.

Jim

jetteroheller

7:09 pm on Mar 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Now is the only problem, how to test it.

Just tried [an on-line page analyzer]

But it seems, they do the request with
accept-encoding gzip
but they do not inflate the compressed delivered file

Header size = 184 bytes
Congratulations! This file was compressed.
View a formatted version of this HTML file, no files reported, loaded by the html file.

HTTP/1.1 200 OK
Date: Tue, 31 Mar 2009 18:32:52 GMT
Server: Apache/1.3.33 (Unix) FrontPage/5.0.2.2635
Transfer-Encoding: chunked
Content-Type: text/html
Content-Encoding: gzip

Seems I have to visit tomorrow an office in Salzburg country government. They have an internet connection with no gzip compression possible.

Somebody there told me last thursday, that visiting my web site looks like to open a zip file in the browser :)

[edited by: jdMorgan at 7:42 pm (utc) on Mar. 31, 2009]
[edit reason] No URLs, please. See Terms of Service, [/edit]

Caterham

8:51 pm on Mar 31, 2009 (gmt 0)

10+ Year Member



Now is the only problem, how to test it.

Telnet, a simple perl/php/whatever script which makes a request... There are some ways.

jetteroheller

7:12 am on Apr 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It works!

Wrote an email to the Austrian National Bibliothek (library)
because their crawler can not understand gzip content.

They just answered me, now works all fine.