Report this

What is the reason for this report?

How to remove .php using NGINX?

Posted on April 26, 2017

http://example.com/Encrypt.php as http://example.com/Encrypt/ I’ve made configuration but i see Error There’s No Page With This Name

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name IP;

location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;

   }

location /calculator {
                index index.php index.html index.htm;
                 if (!-e $fastcgi_script_name) {
                rewrite ^/calculator/(.+)?$ /calculator.php?url=$1 last;
         }
}

location /Encrypt {
                index index.php index.html index.htm;
                 if (!-e $fastcgi_script_name) {
                rewrite ^/Encrypt/(.+)?$ /Encrypt.php?do=$1 last;
         }


}


location /seo {
                 if (!-e $fastcgi_script_name) {
                rewrite ^/seo/(.+)?$ /seo.php?do=$1 last;
         }
 }
location /d65ez46dz {
                index index.php index.html index.htm;
                 if (!-e $fastcgi_script_name) {
                rewrite ^/d65ez46dz/(.+)?$ /d65ez46dz.php?do=$1 last;
         }

}

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

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

}


It works BUT NO DATA ATT ALLLL PLEASE ANY ONE HER FOR HELP THANK’S



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!

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.

The problem could be related with the “using if in nginx is evil”. Which affects “if” when inside a location, mostly.

Instead of doing many “ifs” like that try to make one if and put all those 3 locations inside, if you really need that if at all.

To make the .php disappear use something like this:

location /seo { try_files $uri $uri $uri/ @extensionless-php; } location @extensionless-php { rewrite ^(.*)$ $1.php last; }

This comment has been deleted

I have used this for myself, just a few minor changes for the above answer: https://tufora.com/tutorials/linux/general/remove-php-extension-with-nginx

Give it a go, for me for example if I use https://example.com/name.php it shows 404, that’s expected.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.