I'm trying to convert my legacy php files into a single entrypoint. For now, a few endpoints will require to be operational (10 or so), such as /legacy_endpoint.php. I would like to rewrite these into a different action (post/get etc) on the server.
So far I can rewrite the end point and skip trying to run it as a php file (as the file does not exist):
# rewrite to skip trying to run as PHP file
# use last to search for a new location, which will hit the rule below
location ~ ^/legacy_endpoint.php {
rewrite /(.*) /legacy/endpoint last;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
This runs and serves the index.php file. In the script (Laravel) however I still see the "route", by running dd($request) seen as
requestUri: "/legacy_endpoint.php"
Can I somehow rewrite this into e.g /legacy/endpoint or similar directly in nginx? I'm guessing I'd have to change the request itself?