I'm running a Plesk server with wordpress sites. The site works fine using Apache as webserver and Nginx as a proxy. I want to switch from PHP-FPM handled by Apache to PHP-FPM handled by Nginx so Nginx will be the web server for that site.
I did the switch and I've added this rule:
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php break;
}
Wordpress is running fine. There's also a folder called serp with this .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I need to convert these rules into nginx rewrite rules so both wordpress and the scripts inside that folder will work
Basically the URL that is not working is this:
https://mydomain.tld/serp/2?keyword=tyres&type=test-valerio&source=test-source
While the actual url would be this:
https://mydomain.tld/serp/2.php?keyword=tyres&type=test-valerio&source=test-source
What I've tested so far:
location /serp {
if (!-e $request_filename){
rewrite ^(.*)$ /$1.php break;
}
}
So basically I need a rewrite so instead of using 2.php? in the url to use 2?
I'm not able to make the rewrite rule work. Any help is really appreciated!
In the end I came up with:
location /serp {
try_files $uri $uri/ @extensionless-php;
}
location /article {
try_files $uri $uri/ @extensionless-php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}