Project

General

Profile

URL not processed after url.rewrite-if-not-file

Added by Rothmans over 14 years ago

Hi all,

I am trying to use the mod_rewrite to redirect access to the static javascript files to the gzipped versions of them.
That is, I have a gzipped file, scripts/myscript.js.gz for instance.
The browser requests the /scripts/myscript.js and must treat the response containing the gzipped contents of the /scripts/myscript.js.gz file as a plain normal javascript file.
In order to make that happen the server must add "Content-Encoding: gzip" header and set the "Content-Type" header to the text/javascript value after redirection/rewriting takes place.
I can achieve that (Lighttpd 1.4.28) using the following configuration:

url.rewrite-if-not-file = ( 
    "(^/scripts/[^/]*\.js$)" => "$1.gz" 
    )

$HTTP["url"] =~ "^/scripts/[^/]*\.js$" {
    setenv.add-response-header = ( "Content-Encoding" => "gzip" )
    mimetype.assign = ( "" => "text/javascript" )
}

According to the mod_rewrite documentation http://redmine.lighttpd.net/wiki/1/Docs:ModRewrite the url.rewrite-if-not-file option as well as all other url options "Rewrites a set of URLs internally in the webserver BEFORE they are handled and checks that files do not exist."

That is not true (not happening) as you can see, since if I use the

url.rewrite-if-not-file = ( 
    "(^/scripts/[^/]*\.js$)" => "$1.gz" 
    )

$HTTP["url"] =~ "^/scripts/[^/]*\.js\.gz$" {
    setenv.add-response-header = ( "Content-Encoding" => "gzip" )
    mimetype.assign = ( "" => "text/javascript" )
}
(note added \.gz in the regexp mask) I don't get the desired behavior, as I would expect. I.e. the URL does not get rewritten before the URL is matched against the "$HTTP["url"] =~" rule.

I need the latter option to implement support the "mixed" scenario like when I have a mixture of the .js and .js.gz files and deliver response to the .js caller with headers and content depending of whether the .js file exists of not.

With the current (first) approach even if there is an uncompressed .js file in the folder it gets served back with unneeded and wrong "Content-Encoding" header, which causes errors on the client browser side.

Is that some kind of a bug or I am missing something?
Thank you.


Replies (1)

RE: URL not processed after url.rewrite-if-not-file - Added by Rothmans over 14 years ago

The browser I used for testing is IE8 but the issue is reproducible in FireFox too.
The lighttpd 1.4.28 is cross compiled to run on an ARM Linux embedded platform.

    (1-1/1)