0

I am trying to map friendly URLs to files in a legacy app. There is a file which will receive an action as a parameter to render different sections.

I think that my rewrite condition is wrong because nginx is trying to locate the file including the query string. Here is a section of my conf:

http {
    ...
    map $request_uri $legacy_rewrite {
        ...
        ~^/informativos$ /painel.php?act=ver_informativos;
        ...
    }

    server {
        ...
        location / {
            if ($legacy_rewrite) {
                rewrite ^/(.*)$ $legacy_rewrite break;
            }
        }
    }
}

The problem is that I get this error:

[error] 1132019#0: *28724 open() "[my_app_path]/painel.php?act=ver_informativos;"  failed (2: No such file or directory)

How should I write this rewrite so nginx would understand that I am referencing painel.php?

  • What do your [nginx debug logs](http://nginx.org/en/docs/debugging_log.html) say? – womble Aug 16 '19 at 01:27
  • The only relevant information that I was able to get from debug logs is that, from what I understand, nginx is trying to locate a file name considering the query string that has been set in the _map_ section, I.E: `/painel.php?act=ver_informativos`. As you may see here: `2019/08/22 15:26:03 [debug] 1381218#0: *1974 http output filter "/painel.php?act=ver_mapa?" 2019/08/22 15:26:03 [debug] 1381218#0: *1974 http copy filter: "/painel.php?act=ver_mapa?" 2019/08/22 15:26:03 [debug] 1381218#0: *1974 http postpone filter "/painel.php?act=ver_mapa?" 0000560DEBC48268` – Martignoni Aug 22 '19 at 18:28
  • nginx won't split the remapped rewrite into file/args, also I can't overwrite **$request_uri** or **$query_string** variables. Could it be related to the `location \.php$` block? – Martignoni Aug 22 '19 at 18:31

0 Answers0