Lighttpd rewrite with dot (.) in URL

I've an installation of lighttpd under Debian running a small API. The current rewrite rules are:

url.rewrite = (
    "^/(.*)\.(.+)$" => "$0",
    "^/(.*)$" => "/index.php/$1"
)

The ideia is to (like usual on Apache):

  1. If any static file is called just serve the static file right away;
  2. If a URL is not found as a static file rewrite the request to index.php;

It works fine most of the times, however there's a problem, if the URL contains a DOT . it will just treat it as a static file causing a 404 error (because of the first line).

How can I make sure this doesn't happen and the request is rewritten to index.php? Also there are some conditions:

  • I can't really predict the location of the static files, it should check if the file really exists not just "oh it has a dot, must be static" or "if folder X don't rewrite";
  • The URLs might contain more than one dot, potentially a max of 5.

Thank you.


Solution 1:

Perhaps this can be done using Lighty's server.error-handler-404 option with given index.php as error page. If you are proccessing some additional information about wrong URL (I see /$1 in second rewrite rule) you may try to get this via PHP's SERVER_HTTP_REFERER.