Question

How to remove .php using NGINX?

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


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.

I have tried most everything i saw in stackoverflow and in here ! nothing worked for me.

To make this happend i got a solution after a 8hours research :😂

Real Solution :

add this line in the server { } config (default file or in your domain file.)

location / {
    try_files $uri $uri/ $uri.php?$args;
}

Example :

server {

    location / {
        try_files $uri $uri/ $uri.php?$args;
    }

}

and after adding this restart your server.

service nginx reload

or

systemctl restart nginx

and this is how it works: if i have a url as https://mydomain.com/myfile.php it can be access also with https://mydomain.com/myfile now.

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