0

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.

2 Answers 2

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.

-1
url.rewrite = (
    "^/(.*)\.(.+)$" => "$0",
    "^/(.*)$" => "/index.php/$0/$1"
)
  • REBOOT :
1
  • Could you use edit to expand on why the addition of $0/ in the last line makes this a good suggestion? I suspect you're right, but some explanation would certainly help future readers.
    – Criggie
    Jan 6, 2022 at 3:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .