2

I'm trying to configure the rewrite rules for lighttpd so that a specific cakephp controller-action is executed if a file is not found. The controller-action will generate the data (png file), save it for future use, and then serve it to the client. The next time someone tries to access the file, it will be served by lighttpd directly without executing any php. In other words, the png files are cached so there is no need to recreate them.

From what I can tell, url.rewrite-if-not-file is ignored if rewrite-once has a match. Thus, the following can serve up my cached files but not my uncached files.

url.rewrite-if-not-file = (
  "^/scan/(.+)\.png" => "/mycontroller/scan/$1"
)

url.rewrite-once = (
  "^/(css|files|img|js)/(.*)" => "/$1/$2",
  "^/favicon.ico" => "/favicon.ico",    
  "^/scan/(.+\.png)" => "/scan/$1",
  "^([^\?]*)(\?(.+))?$" => "/index.php?url=$1&$3",
)

The only solution I can think of now is to delete the 3rd rule and modify ^([^\?]*)(\?(.+))?$ so it ignores urls starting with \scan\.

Any other suggestions?

Lawrence Barsanti
  • 31,929
  • 10
  • 46
  • 68
  • Could you not instead make CakePHP use a custom error page that redirects you appropriately? http://stackoverflow.com/questions/9620363/cakephp-2-0-how-to-make-custom-error-pages – Kai Sep 12 '13 at 23:21
  • 1
    I could do this with cake but the idea is to have the webserver serve the cached images without executing any php. I'm guessing that it will be faster. – Lawrence Barsanti Sep 14 '13 at 13:29
  • Why is this question tagged as CakePHP? – Dave Nov 18 '13 at 21:35

1 Answers1

0

i'd do something like this in a controller:

if (file_exists($file_name)) {
    $this->redirect($file_name);
} else {
    $this->redirect(array('action' => 'some_action', 'controller' => 'some_controller'));
}
Chris Pierce
  • 706
  • 5
  • 9