删除文件扩展名并保留nginx上的参数

删除文件扩展名并保留nginx上的参数,nginx,nginx-config,nginx-location,Nginx,Nginx Config,Nginx Location,我试图使我的服务器搜索引擎优化友好的网址 原始:/face.php?name=hello-stackoverflow123 所需:/face/hello-stackoverflow123 我做了一些小配置: location / { try_files $uri $uri.html $uri/ @extensionless-php; index index.html index.htm index.php; } location ~ \.

我试图使我的服务器搜索引擎优化友好的网址

原始:/face.php?name=hello-stackoverflow123

所需:/face/hello-stackoverflow123

我做了一些小配置:

    location / {
        try_files $uri $uri.html $uri/ @extensionless-php;
        index index.html index.htm index.php;
    }

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

    location @extensionless-php {
        rewrite ^(.*)$ $1.php last;
    }
问题1:我找不到一个配置来保持它给我的参数总是404(所以如果我尝试face/hello-stackoverflow123,我会得到404)


问题2:如果我有一个文件faces.php,如果我尝试/faces,它会打开,但是如果我打开faces.php,它不会从您提供的示例URI
/face/hello-stackoverflow123
重定向到/faces

,如何确定这个URI应该作为
/face/hello stackoverflow.php
还是作为
/face.php?name=hello-stackoverflow123
?您的配置将只尝试
/face/hello stackoverflow.php
,这就是它的工作方式。当然它不会将您从
/faces.php
重定向到
faces
,它不应该这样做。整个问题听起来很奇怪,就像“我在谷歌上发现了一些东西,但它没有按我希望的方式工作,为什么?”如果你想获得一些帮助,你至少应该指定请求处理规则,例如,“对于请求
/a/b/c
尝试
/a/b/c.php
,然后
/a/b.php?arg=c
,然后
/a.php?arg1=b&arg2=c
,然后是404错误否则,你将完全不清楚你想要实现什么。