URL Rewrite to Remove .php in my Nginx PHP-FPM URL Rewrite to Remove .php in my Nginx PHP-FPM nginx nginx

URL Rewrite to Remove .php in my Nginx PHP-FPM


My question is, where should I insert the code above?

The server block for your domain contains one location block. The other two location blocks need to be added to that same server block.

For example:

server {    server_name example.com www.example.com;    root /home/mydomain/public_html;    ...    location / {        try_files $uri $uri.html $uri/ @extensionless-php;        index index.html index.htm index.php;    }        location @extensionless-php {        rewrite ^ $1.php last;    }    location ~ \.php$ {        try_files $uri =404;        fastcgi_pass localhost:8000;    }    ...}

But conflicting server name error still exist. What is the solution?

Use nginx -T (that's an uppercase T) to test the Nginx configuration file and view the entire configuration across all the included files. Inspect the server_name directives and identify where the duplicated name is coming from.

Just because your distribution includes include directives and directories to help organise your configuration across multiple files, you do not need to use them. Keeping the entire configuration in a single nginx.conf can be convenient for simpler servers.


Hello make the following modifications

remove from your code:

@extensionless-php; location @extensionless-php {       rewrite ^ $1.php last;   }.php$ {


server {server_name example.com www.example.com;root /home/mydomain/public_html;...location / {            # This is cool because no php is touched for static content.            # include the "?$args" part so non-default permalinks doesn't break when using query string            try_files $uri $uri/ /index.php?$args;    }    location ~ \.php$ {    try_files $uri =404;    fastcgi_pass localhost:8000;    }