I want to make a Nginx rewrite rule for parameters pretending to be top-level directories. For instance, I want example.org/myval
to be redirected to example.org/foo.php?param=myval
, but at the top level I already have some other files (like index.php
) I would like to be reachable.
My attempt is:
location = ^/(?!.*)$ {
rewrite ^/$ https://example.org/index.php break;
}
location = ^/(.*) {
rewrite /(.*) /foo.php?param=$1 last;
}
the 1st rule catching only root, the second trying to catch pretending top-levels (but failing),so all I get when accessing non-(something.php) files is a 404. Any ideas?
EDIT: Later I have the PHP block:
location ~ ^/(index|signup|login|).php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
which I've come to know contains the try_files
part (but shouldn't match anything else); I don't know where does the 404 come from.