0

I have tried many ways to remove my php extension but unable to do so, here is what I'm trying to achieve.

https://google.com/users/login.php > https://google.com/users/login

Sounds easy but I can't seems to remove it, either I received 500 internal error or 404 error

        location  /users/ {
#               try_files $uri $uri/ =404;
                rewrite ^/users/(.*) /users/(.*).php$1 break;
        }

        location ~ \.php$ {
#               try_files $uri =404;
                include snippets/fastcgi-php.conf;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
1

A static solution would be:

location /users/login {
    try_files $uri $uri.php =404;
}

If you want it more dynamic you have to put it into your / location, so it would always try to deliver the request from the filesystem, if the resource of the url on the filesystem does not exist, it tries to solve the url with .php as suffix:

location / {
    try_files $uri $uri.php =404;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.