0

Im not a SysAdmin so i don't really understand how its work to do what I want. But I have a PHP website with .php file and I want to remove the .php in URL.

On apache its easier but nginx is better so i want to know how to do this on nginx.

Here is my config:

server {
    listen 80;
    server_name xx.com www.xx.com;
    root /var/www/xx;

    index index.html index.htm index.php;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }

}

Thank you all

3

1 Answer 1

2

Add $uri.php$is_args$query_string to the end of / location:

location / {
    try_files $uri $uri/ $uri.php$is_args$query_string;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.