Wordpress NGINX Plesk rewrite rules + rewrite for a specific folder

admin

Administrator
Staff member
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:

Code:
if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php break;
}

Wordpress is running fine. There's also a folder called serp with this .htaccess file:

Code:
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:

Code:
https://mydomain.tld/serp/2?keyword=tyres&type=test-valerio&source=test-source

While the actual url would be this:

Code:
https://mydomain.tld/serp/2.php?keyword=tyres&type=test-valerio&source=test-source

What I've tested so far:

Code:
location /serp {
  if (!-e $request_filename){
    rewrite ^(.*)$ /$1.php break;
  }
}

So basically I need a rewrite so instead of using <strong>2.php?</strong> in the url to use <strong>2?</strong>

I'm not able to make the rewrite rule work. Any help is really appreciated!