Question

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

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;
    }
}

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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