How to make nginx + php-fpm behave like apache on ".php/args" requests

September 25, 2019 85 views
Nginx Apache PHP

Consider the following example URI

http://teste.com/test.php/8455

When accessing this on Apache the apache send the request to the “test.php” file. However when accessing the same URI on nginx with php-fpm he gave an not found error, why does it behaves different and how can i make they have the same behavior ?

This is my .htacces redirect configuration:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{ENV:REDIRECT_STATUS} 200 [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

And this is my nginx server configuration

server {
    listen   80;
    root /var/www/html;
    index index.php index.html;
    location ~ .php$ {
            try_files $request_uri $request_uri/ =404;
            fastcgi_pass 127.0.0.1:10000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location / {
        try_files $request_uri =404;
    }


    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/www;
    }
}
1 Answer

Hi @allangodoys,

I’ll suggest making the requests like


http://teste.com/test.php?8455=something 

or 

http://teste.com/test.php?8455

As I believe this is the proper way of handling such requests. If you want to keep the current convention, try to pass the $query_string variable in nginx:

try_files $uri $uri/ /index.php/$query_string;

Kind regards,
Kalin

Have another answer? Share your knowledge.