Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm running lighttpd 1.4.33, which is reverse proxied to from an Apache server that is open to the Internet. When accessing a script from the local address of the lighttpd server, GET parameters are passed to the script just fine, and I get the expected result. However, when the script is accessed through the proxy (and is rewritten by the following lighttpd rule), the query parameters seem to be dropped completely.

The rewrite rule that seems to be causing the problem:

$HTTP["host"] =~ "^site\.example\.com$" {
        # This affects the requests that aren't rewritten below, ie. static stuff
        server.document-root = "/var/www/example/public"   
        url.rewrite-once = ( "^((?!assets).)*$" => "index.php/$1" )
}

Which is supposed to rewrite all URLs so they are passed through the routing engine in index.php, except the static stuff in the /assets directory, which should just be served statically. Note that /assets is a subdir of /var/www/example/public, so this works correctly.

Lighttpd debug log for the request with the dropped parameter:

2014-07-23 11:36:46: (response.c.310) Request-URI  :  /foo/bar?someparam=data 
2014-07-23 11:36:46: (response.c.311) URI-scheme   :  http 
2014-07-23 11:36:46: (response.c.312) URI-authority:  site.example.com 
2014-07-23 11:36:46: (response.c.313) URI-path     :  /foo/bar 
2014-07-23 11:36:46: (response.c.314) URI-query    :  someparam=data 
2014-07-23 11:36:46: (response.c.309) -- splitting Request-URI 
2014-07-23 11:36:46: (response.c.310) Request-URI  :  index.php/a
2014-07-23 11:36:46: (response.c.311) URI-scheme   :  http 
2014-07-23 11:36:46: (response.c.312) URI-authority:  site.example.com 
2014-07-23 11:36:46: (response.c.313) URI-path     :  index.php/a 
2014-07-23 11:36:46: (response.c.314) URI-query    :

Note the blank URI-query field on the last line. It seems as though the step "splitting the request URI" is breaking everything.

Any ideas on what could be causing this?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

It turns out that there is a simpler way to do this on lighttpd >= 1.4.24. You can use the url.rewrite-if-not-file directive, like so (lighttpd <= 1.4.33):

$HTTP["host"] =~ "^site\.example\.com$" {
        # Rewrite all requests to non-physical files
        url.rewrite-if-not-file =
        (
            "^(.*)$" => "index.php/$1"
        )
}

That example uses the $HTTP["host"] directive, as using the $HTTP["url"] directive was unsupported up until 1.4.34. In lighttpd >= 1.4.34, you can use it in a URL conditional block:

$HTTP["url"] =~ "^\/site/$" {
        # Rewrite all requests to non-physical files
        url.rewrite-if-not-file =
        (
            "^(.*)$" => "index.php/$1"
        )
}

I guess if you're well and truly forced to use lighttpd <= 1.4.24, you can always use mod_magnet and Lua.

share|improve this answer
    
$HTTP["url"] never includes the hostname. –  Stefan Jul 24 at 17:44
    
@Stefan oops, thanks. Fixed. –  Libbux Jul 25 at 13:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.