0

I have a 20-rewrite.conf for my php application looking like this:

$HTTP["host"] =~ "www.mydomain.com" {
    url.rewrite-once += (
        "^/(img|css)/.*" => "$0",
        ".*" => "/my_app.php"
    )
}

I want to be able to put the webserver in kind of a "maintenance" mode while I update my application from scm. To do this, my idea was to enable an additional rewrite configuration file before this one. The 16-rewrite-maintenance.conf file looks like this:

url.rewrite-once += (
    "^/(img|css)/.*" => "$0",
    ".*" => "/maintenance_app.php"
)

Now, on the maintenance page, I have a logo that doesn't get loaded. I get a 404 error. Lighttpd debug says the following:

2012-12-13 20:28:06: (response.c.300) -- splitting Request-URI 
2012-12-13 20:28:06: (response.c.301) Request-URI  :  /img/content/logo.png 
2012-12-13 20:28:06: (response.c.302) URI-scheme   :  http 
2012-12-13 20:28:06: (response.c.303) URI-authority:  localhost 
2012-12-13 20:28:06: (response.c.304) URI-path     :  /img/content/logo.png 
2012-12-13 20:28:06: (response.c.305) URI-query    :   
2012-12-13 20:28:06: (response.c.300) -- splitting Request-URI 
2012-12-13 20:28:06: (response.c.301) Request-URI  :  /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.302) URI-scheme   :  http 
2012-12-13 20:28:06: (response.c.303) URI-authority:  localhost 
2012-12-13 20:28:06: (response.c.304) URI-path     :  /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.305) URI-query    :   
2012-12-13 20:28:06: (response.c.349) -- sanatising URI 
2012-12-13 20:28:06: (response.c.350) URI-path     :  /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (mod_access.c.135) -- mod_access_uri_handler called 
2012-12-13 20:28:06: (response.c.470) -- before doc_root 
2012-12-13 20:28:06: (response.c.471) Doc-Root     : /www
2012-12-13 20:28:06: (response.c.472) Rel-Path     : /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.473) Path         :  
2012-12-13 20:28:06: (response.c.521) -- after doc_root 
2012-12-13 20:28:06: (response.c.522) Doc-Root     : /www 
2012-12-13 20:28:06: (response.c.523) Rel-Path     : /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.524) Path         : /www/img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.541) -- logical -> physical 
2012-12-13 20:28:06: (response.c.542) Doc-Root     : /www
2012-12-13 20:28:06: (response.c.543) Rel-Path     : /img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.544) Path         : /www/img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.561) -- handling physical path 
2012-12-13 20:28:06: (response.c.562) Path         : /www/img/content/logo.png, /img/content/logo.png 
2012-12-13 20:28:06: (response.c.618) -- file not found 
2012-12-13 20:28:06: (response.c.619) Path         : /www/img/content/logo.png, /img/content/logo.png 

Any clue on why lighttpd matches both rules (from my application rewrite config and from my maintenance rewrite config) and concatenates them with a comma - that doesn't seem to make any sense?! Shouldn't it stop after the first match with rewrite-once?

netmikey
  • 233
  • 1
  • 2
  • 7
  • the conditional rewrite will catenate both rewrite rulesets since you are using +=, ending up with two instances of an identical regex... also (not having touched lighty for a while) I would not be so sure how two += behave when they both have lists with the first not having a final comma... – rackandboneman Dec 14 '12 at 01:12

1 Answers1

1

url.rewrite is an associative array (hash,dict, whatever). "Adding" another array with duplicate keys means the values will get concatenated with a comma (like you would merge duplicate http headers).

lighttpd -p -f /etc/lighttpd/lighttpd.conf

is a good way to find out how lighttpd sees your config.

Edit:

To enable the maintenance rules, i'd add a conditional block at the end of the config (the last active block wins)

$HTTP["host"] =~ "www.mydomain.com" {
    url.rewrite-once = (
        "^/(img|css)/.*" => "$0",
        ".*" => "/maintenance_app.php"
    )
}
Stefan
  • 819
  • 1
  • 7
  • 18
  • Thank you for the good explanation Stefan! The obvious follow-up question is: how can I achieve the maintenance-rewrite behavior I explain in the main post? If you could help me and add that to your response, that'd be perfect :) – netmikey Dec 15 '12 at 12:56
  • @netmikey i edited my answer some time ago, did you try it? – Stefan Jan 07 '13 at 23:58